Android Aptitude练习应用

时间:2013-10-24 17:45:48

标签: android

我想开发一个aptitude app .. 为了在我的文本视图中我必须显示第一个问题..点击下一个按钮我必须显示第二个问题..再次点击相同的下一个按钮第三个问题必须显示..喜欢我想显示30个问题。 .all问题应该显示在单个java文件中。我试图显示两个问题。但对于多个问题,我找不到代码..

  package com.example.asl;
  import java.util.Arrays;
  import java.util.Random;

 import android.app.Activity;
 import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.TextView;

  public class Aptitude extends Activity {
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.aptitude);
    Button b=(Button) findViewById(R.id.button1);
    final TextView tv=(TextView) findViewById(R.id.textView1);
    final String Question[]={"what is UR Name","What is ur Age","Whats ur Qualification"};
    Button btnNext = (Button) findViewById(R.id.button1);
     final TextView cumulos = (TextView) findViewById(R.id.textView1);
        //TextView respostas = (TextView)findViewById(R.id.respostas);

        Random randPhrase = new Random();
        final String[] cum = {"what is UR Name","What is ur Age","Whats ur Qualification"};
        //String[] resp = getResources().getStringArray(R.array.resp_cumulos);

        String textout = "";
        String textresp = "";

    //Button btnPrevious = (Button) findViewById(R.id.yourPreviousbutton);

    btnNext.setOnClickListener(new OnClickListener(){

         public void onClick(View arg0) {
             int i = 0;
              if(i<cum.length-1){
                   i+=1;
                   cumulos.setText(cum[i]);
                  // respostas.setText(resp[i]);
              }

         }


    });
    //btnPrevious.setOnClickListener(new OnClickListener(){

         //public void onClick(View arg0) {
              //if(i>0){
                  // i-=1;
                 //  cumulos.setText(cum[i]);
                  // respostas.setText(resp[i]);
             // }

        // }


    //});

}

  }

enter code here

1 个答案:

答案 0 :(得分:2)

onClick()中初始化您的计数器总是会重置它

onClick()之外对其进行初始化,并按原样在onClick()中递增。

public class Aptitude extends Activity {

   int i = 0;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aptitude);
        Button b=(Button) findViewById(R.id.button1);
        ...
   }

     public void onClick(View arg0) {  // rename arg0 to something meaningful 
                                       // like v or view for readibility
     //    int i = 0;   remove this guy
          if(i<cum.length-1){
               i+=1;
               cumulos.setText(cum[i]);

如果这不能解决您的问题,那么请解释问题是什么,但我确信这部分会给您带来麻烦。