Loading...

Thursday, 9 August 2012

Add Button to Activity (Android)

package app.Test;

import java.util.ArrayList;
import java.util.List;

import com.test.android.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.Toast;

public class appTest extends Activity {
    private Button btn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        BtnListener();
    }
    private void BtnListener() {
        btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener(){
            public void onClick(View arg0){
                Toast.makeText(this, "Welcome", Toast.LENGTH_SHORT).show();
            }
        });
    }   
}

No comments:

Post a Comment