public class ClientGame extends Activity implements OnClickListener{
Button Answer1, Answer2, Answer3, Answer4;
TextView txtQuest;
DatabaseHelper dbHelper;
Cursor cur;
String qid;
String[] _ids = {};
ArrayList<String> idList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.clientgame);
dbHelper = new DatabaseHelper(this);
cur = dbHelper.getRandomQuestion();
startManagingCursor(cur);
qid = cur.getString(cur.getColumnIndex(DatabaseHelper.colID));
idList = new ArrayList<String>();
idList.add(qid); // i take the current id
try
{
Intent extras = getIntent();
String ID = extras.getStringExtra("_id");
idList.add(ID); // add the previous one
_ids = (String[]) idList.toArray(new String[0]);
score = (TextView)findViewById(R.id.textView2);
score.setText("Your score is " + idList);
}
catch(Exception e)
{
}
Answer1 = (Button) findViewById(R.id.button1);
Answer1.setText(answer1);
Answer1.setOnClickListener(this);
Answer2 = (Button) findViewById(R.id.button2);
Answer2.setText(answer2);
Answer2.setOnClickListener(this);
Answer3 = (Button) findViewById(R.id.button3);
Answer3.setText(answer3);
Answer3.setOnClickListener(this);
Answer4 = (Button) findViewById(R.id.button4);
Answer4.setText(answer4);
Answer4.setOnClickListener(this);
}
@Override
public void onPause() {
super.onPause();
finish(); }
@Override
public void onClick(View view) { //correct answer check and store skore and id
if (view == findViewById(R.id.button1))
{
int i = 1;
String ID = cur.getString(cur.getColumnIndex("_id"));
Intent ini = new Intent(ClientGame.this, ClientGame.class);
ini.putExtra("_id", ID);
startActivity(ini);
}
if (view == findViewById(R.id.button2))
{
int i = 1;
String ID = cur.getString(cur.getColumnIndex("_id"));
Intent ini = new Intent(ClientGame.this, ClientGame.class);
ini.putExtra("_id", ID);
startActivity(ini);
}
if (view == findViewById(R.id.button3))
{
int i = 1;
String ID = cur.getString(cur.getColumnIndex("_id"));
Intent ini = new Intent(ClientGame.this, ClientGame.class);
ini.putExtra("_id", ID);
startActivity(ini);
}
if (view == findViewById(R.id.button4))
{
int i = 1;
String ID = cur.getString(cur.getColumnIndex("_id"));
Intent ini = new Intent(ClientGame.this, ClientGame.class);
ini.putExtra("_id", ID);
startActivity(ini);
}
}
这里的问题是在 textview 上只显示了两个 id。最后一个和当前。我想显示用户想要的所有ID。当然不是无限的。那么我如何创建一个数组列表,假设有十个值,并且每次都存储 id?