Click here to Skip to main content
15,886,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
EditText psw;
EditText logn;
TextView textIn;
TextView pass;
Button buttonCancel;
Panel pnl;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.text_enter);
        buttonCancel = (Button)findViewById(R.id.Cancel);
        buttonCancel.setOnClickListener(buttonCancelOnClickListener);
        
        setContentView(R.layout.activity_main2);
        textIn = (TextView)findViewById(R.id.textin);
        textIn.setText("Login:");
        logn = (EditText)findViewById(R.id.logn);
        pass = (TextView)findViewById(R.id.pass);
        pass.setText("Password:");
        psw = (EditText)findViewById(R.id.psw);
        Button buttonSend = (Button)findViewById(R.id.send);
        buttonSend.setOnClickListener(buttonSendOnClickListener);
        pnl = new Panel(this);
    }
    Button.OnClickListener buttonCancelOnClickListener
    = new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) { 
	   try{
	   setContentView(pnl);
	   }catch(Exception x)
	   {
		   x.toString();
	   }
   }
   };

OnClickListener doesn't executes, why and how to fix?
Posted

Try with something like this..
Java
private Button btn1
private Button btn2;
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.yourPage);

    btn1=(Button)findViewById(R.id.btn_1);
    btn2=(Button)findViewById(R.id.btn_2);

    btn1.setOnClickListener(this);
    btn2.setOnClickListener(this);

}
public void onClick(View v) {
    // TODO Auto-generated method stub

    switch (v.getId()) {

    case R.id.btn_1:
                   //do your button 1 work here
        break;
    case R.id.btn_2:
                   //do your button 2 work here
        break;
     }
 
Share this answer
 
Comments
[no name] 27-Nov-12 6:11am    
Thanks, but your code works ONLY if all buttons are in the same UI(activity), so it's doesn't work in my case(multi-UI), unfortunately, I don't know why...
please follow that link supported with video and there are many videos that cover almost every thing in android
thenewboston
enjoy it >>>
 
Share this answer
 
Comments
[no name] 6-Dec-12 10:07am    
Thanks, but your code works ONLY if all buttons are in the same UI(activity), so it's doesn't work in my case(multi-UI), unfortunately, I don't know why...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900