为什么我按一下按钮后按钮不起作用? [英] Why button doesn't work when I klicked on it ?

查看:71
本文介绍了为什么我按一下按钮后按钮不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 EditText psw;
EditText登录;
TextView textIn;
TextView通过;
按键按键取消;
面板PNL;

     @ Override 
    公共 无效 onCreate(捆绑保存的InstanceState){
        超级 .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(" );
        logn =(EditText)findViewById(R.id.logn);
        通过=(TextView)findViewById(R.id.pass);
        pass.setText(" );
        psw =(EditText)findViewById(R.id.psw);
        按钮buttonSend =(Button)findViewById(R.id.send);
        buttonSend.setOnClickListener(buttonSendOnClickListener);
        pnl = 面板();
    }
    Button.OnClickListener buttonCancelOnClickListener
    =  Button.OnClickListener(){

    @ Override 
   公共 无效 onClick(查看arg0){
尝试 {
setContentView(pnl);
} 捕获(异常x)
{
x.toString();
}
   }
   }; 


解决方案

尝试使用类似这样的方法..

 私有按钮btn1
私有按钮btn2;
 @ Override 
公共 无效 onCreate(捆绑保存的InstanceState)
{
    超级 .onCreate(savedInstanceState);
    setContentView(R.layout.yourPage);

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

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

}
公共 无效 onClick(查看v){
    //  TODO自动生成的方法存根

    开关(v.getId()){

    案例 R.id.btn_1:
                   // 在此执行按钮1的操作
         break ;
    案例 R.id.btn_2:
                   // 在此执行按钮2的操作
         break ;
     }


请遵循该视频支持的链接,并且有很多视频涵盖了android中几乎所有内容
thenewboston
享受>>>


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?

解决方案

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;
     }


please follow that link supported with video and there are many videos that cover almost every thing in android
thenewboston
enjoy it >>>


这篇关于为什么我按一下按钮后按钮不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆