简体   繁体   中英

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将焦点传递给按钮

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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