Android Button Onclick

后端 未结 9 2068
猫巷女王i
猫巷女王i 2020-11-29 03:41

OK I\'m new to android dev\'s and Java, so I\'m having problems with on click method here\'s my code. I know I\'ve gotta be close, thanks in advance. All I want my button to

9条回答
  •  星月不相逢
    2020-11-29 04:23

    If you write like this in Button tag in xml file : android:onClick="setLogin" then

    Do like this:

    
    
    
    

    and in Code part:

    public class StartUpActivity extends Activity 
    {
        public void onCreate(Bundle savedInstanceState) 
        {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);    
        }
    
        public void onClickBtn(View v)
        {
            Toast.makeText(this, "Clicked on Button", Toast.LENGTH_LONG).show();
        } 
    }
    

    and no need all this:

     Button button = (Button) findViewById(R.id.button1);
     button.setOnClickListener(new OnClickListener() {
    
        public void onClick(View v) {
            // TODO Auto-generated method stub
    
        }
     });
    

    Check it once;

提交回复
热议问题