2013-08-02 126 views
0

这是我的代码。在这段代码中,我试图改变一个按钮上的四个文本的内容,第一次单击,并在同一按钮单击我试图改变只有三个textview的内容。但它不起作用。需要帮助来改变按钮点击的textview内容

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(""); 
    } 
+0

if(test == 1)when test is getting one .... – Sandy09

+0

...关于第二个按钮点击 – gunar

+0

但t1按钮将始终具有相同的值 – gunar

回答

0

您可以在onClick中增加一个计数器并根据计数器值更改视图吗?