简体   繁体   English

需要帮助来更改单击按钮时的textview内容

[英]Need help to change the textview content on button click

This is my code. 这是我的代码。 In this code I am trying to change the content of four text on a button click on first time and on same button click I am trying to change the content of only three textview. 在这段代码中,我试图更改第一次单击时的四个文本的内容,而单击同一按钮时,我尝试更改仅三个textview的内容。 But it's not working. 但这不起作用。

public class Home_page_Activity extends Activity {
    Button next;
    int textids[]={R.id.text1,R.id.text2,R.id.text3,R.id.text4};
    String Question[]={"1","2","3","4"};
    String three[]={"7","27","37"};

    TextView t1,t2,t3,t4,t5,t6,t7;
    int count=0;
    int check=0;
    //int button_id[]={R.id.next};
    //Button btn[];
    int test=0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_page_);
        t1=(TextView)findViewById(R.id.text1);
        t2=(TextView)findViewById(R.id.text2);
        t3=(TextView)findViewById(R.id.text3);
        t4=(TextView)findViewById(R.id.text4);
        t5=(TextView)findViewById(R.id.text5);
        t6=(TextView)findViewById(R.id.text6);
        t7=(TextView)findViewById(R.id.text7);
        next=(Button)findViewById(R.id.next);


        next.setOnClickListener(new OnClickListener() {


            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(test==1)
                {
                        String get=(String) t1.getText();
                    //int inter=Integer.parseInt(get);
                    Log.i("t1", get);
                    t1.setText("");
                    t2.setText("");
                    t3.setText("");
                    t4.setText("");
                    threetext();
                }
                nextquestion();



            }
        });
        }


    public void nextquestion()
    {


            t1.setText(Question[count]);
            t2.setText(Question[count+1]);
            t3.setText(Question[count+2]);
            t4.setText(Question[count+3]);
            Log.i("count", "value"     +count);

        test++;

    }

    public void threetext()
    {
        Log.i("threetext", "working");

        t1.setText(three[check]);
        t2.setText(three[check+1]);
        t3.setText(three[check+2]);
        t4.setText("");
    }

您能否在onClick中增加一个计数器并根据该计数器的值更改视图?

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

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