On Button Click how to increment counter and show in textview

前端 未结 4 2015
天涯浪人
天涯浪人 2021-01-22 06:58

I am working on a shopping cart assignment for that I have created a custom ListView that contains the Picture, Price and Add to Cart button in each row. I also have a textview

4条回答
  •  萌比男神i
    2021-01-22 07:35

    we have to set value runOnUiThread of that Controls. like this.. May this help you.

    btn.setOnClickListener(new View.OnClickListener() 
    {
    
                @Override
                public void onClick(View v) {
                        count++;
                       setTimertext(count);
    
            }
            });
    
    public void setTimertext(String strValue) {         
            runOnUiThread(new Runnable() {
                public void run() {
    
                    txt.setText(String.valueOf(strValue));    
                }
            });
        }
    

提交回复
热议问题