In your main.xml file, create the button like this:-
<Button android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myClickHandler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myClickHandler"
android:text="Click Me"/>
Then in your .java file, put this code:-
public class buttonclick extends Activity
{
private Button btnclickme;
{
private Button btnclickme;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnclickme = (Button) findViewById(R.id.Button01);
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnclickme = (Button) findViewById(R.id.Button01);
btnclickme.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
{
public void onClick(View v)
{
//what happen when click
//put your code here
}
});
}
}
});
}
}
How's that? Hope that's helpful.
No comments:
Post a Comment