Jacky Choo
Jacky Choo

Reputation: 144

OnClickListener directly change the page once clicked the button

Any experts here are able to help me, i wanted to change the number in edittext, add or minus the number inside directly once i click on the buttons. But there are error once i clicked on the buttons, how do i change the current UI directly without refreshing the page by clicking on the button?

for(int x=0; x<itemAmt; x++){
    final int f=x;
    btn[0][x].setOnClickListener(new Button.OnClickListener(){

        public void onClick(View v) {

            int num=Integer.parseInt(et[f].getText().toString());

            et[f].setText(num+1);
        }

    });

    btn[1][x].setOnClickListener(new Button.OnClickListener(){
        public void onClick(View v) {

            int num=Integer.parseInt(et[f].getText().toString());

            et[f].setText(num-1);

        }

    });
}

Upvotes: 0

Views: 78

Answers (1)

yyunikov
yyunikov

Reputation: 5907

Try to use these methods:

    int num=Integer.valueOf(et[f].getText().toString());

    et[f].setText(Integer.toString(num+1));

and

    int num=Integer.valueOf(et[f].getText().toString());

    et[f].setText(Integer.toString(num-1));

Upvotes: 2

Related Questions