Button Clicking -Perform Action in android
Button Clicking -Perform Action in android
Example: click on button will fill the some text in textField
Output :
activity_main.xml
MainActivity.java
Example: click on button will fill the some text in textField
Output :
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/Generate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="167dp"
android:text="@string/generate_author_name"
/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/Generate"
android:layout_centerHorizontal="true"
android:layout_marginBottom="21dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</RelativeLayout>
MainActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements View.OnClickListener
{
Button gen;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//display content of activity_main.xml
setContentView(R.layout.activity_main);
// identify the button already created in "activity_main"
gen=(Button) findViewById(R.id.Generate);
//set click listener for button
gen.setOnClickListener(this);
}
public void onClick(View v)
{
// identify textbox already created in "activity_main"
EditText textBox=(EditText) findViewById(R.id.editText1);
//fill text in textbox
textBox.setText("padmanLabs");
}
}
Hi,
ReplyDeleteI see you have some posts about Android, so I want to ask you this question.
Maybe you know some useful and straightforward android's tutorial ?
I have one app in mind I would like to develop, rather simply, but don't want to get lost somewhere when trying to get Android philosophy understood...,
thanks in advance
@kornicameister
Kambi - Online Casino | Casino - Kadang Pintar
ReplyDeleteKambi offers a unique atmosphere in online gaming for a wide range of online casino games. The main goal of this casino kadangpintar is worrione to satisfy your needs 메리트 카지노