Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Android
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 26-Nov-12 8:55am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try with something like this..
	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;
         }
  Permalink  
Comments
halabella at 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...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

please follow that link supported with video and there are many videos that cover almost every thing in android
thenewboston
enjoy it >>>
  Permalink  
Comments
halabella at 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)



Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid