2013-08-02 90 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中增加一個計數器並根據計數器值更改視圖嗎?