简体   繁体   English

android按钮需要2点击才能生效

[英]android button needs 2 click to make effect

I have encounter strange behavior of the button. 我遇到了按钮的奇怪行为。 Button has two action. 按钮有两个动作。

  • First action is to set text inside button and 第一步是在按钮内设置文本,然后
  • second to Change integer value. 第二个更改整数值。

    When I click once, only integer value is changed. 当我单击一次时,仅整数值被更改。 Text is changed only after second click on it. 文本仅在第二次单击后才更改。 Help me please to fix it :) 帮助我,请解决它:)

button layout 按钮布局

<Button
android:id="@+id/delres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_below="@id/soffice"
android:layout_toRightOf="@id/face"
android:onClick="delrestor_Click"
android:text="Button"
/>

code for button 按钮代码

public void delrestor_Click(View v){
        db = new DatabaseHandler(this);  
        if(p.get_active()==1){
            p.set_active(0);
            p.set_ranking(0);
            dres.setText("Delete");
            db.updateCandidate(p);
        }
        else{
            p.set_active(1);
            p.set_ranking(0);
            dres.setText("Restore");
            db.updateCandidate(p);
        }
        db.close();
    }

button initialization 按钮初始化

dres = (Button) findViewById(R.id.delres);
if(p.get_active()==1){
            dres.setText("Delete");
        }
        else dres.setText("Restore");

android:dublicateParentState将焦点传递给按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM