How to Use Button Click

Posted by Unknown Minggu, 03 April 2011 0 komentar
Button is the most commonly use function to fire up an event or action. We'll show an example to use button with android. How to get an action when you click on a button?


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:text="Click Me"/>


Then in your .java file, put this code:-

public class buttonclick extends Activity
{
    private Button btnclickme;    

    @Override
    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)            
            {
                 //what happen when click            
                 //put your code here
             }
         });               
    }
}



How's that? Hope that's helpful.
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: How to Use Button Click
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://androidemoticonss.blogspot.com/2011/04/how-to-use-button-click.html. Terima kasih sudah singgah membaca artikel ini.

0 komentar:

Posting Komentar

Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android emoticons.