【发布时间】:2018-06-14 05:20:00
【问题描述】:
我正在寻找一个对我的应用程序有用的选项,基础很简单,当我们单击问题时,我有一个问题列表(在 listView 中),我们还有另一个包含问题详细信息和答案的活动即设置(真或假),如果答案是正确的,我想将列表视图中的问题着色为绿色,如果为错误则为红色:
我生成问题的代码:
public void showQuest(View view){
ModelHelper md = new ModelHelper(this);
db = openHelper.getWritableDatabase();
Spinner s = (Spinner) findViewById(R.id.spn_ques);
Integer para = 2;
para = Integer.parseInt( s.getSelectedItem().toString()) ;
ArrayList<String> lstQ = md.getOnlyQuestions(para);
ArrayAdapter lstad = new ArrayAdapter(this, android.R.layout.simple_list_item_1,lstQ);
lst.setAdapter(lstad);
listView OnclickListener:
String quest = (String) parent.getAdapter().getItem(i);
int pos = lst.getCheckedItemPosition();
Intent inte = new Intent(view.getContext(),Reponse.class);
cursor = db.rawQuery("SELECT * FROM "+ ModelHelper.TABLE_QUESTION + " WHERE " + ModelHelper.KEY_QUESTION + " = ? ",new String[] {quest});
if (cursor != null)
if (cursor.getCount() > 0) {
cursor.moveToFirst();
final Intent intent = getIntent();
String matr= intent.getStringExtra("id");
String repA = cursor.getString(cursor.getColumnIndex(ModelHelper.KEY_PROFIL_WAITEDANSWER));
String cible = cursor.getString(cursor.getColumnIndex(ModelHelper.KEY_PROFILE));
String plan = cursor.getString(cursor.getColumnIndex(ModelHelper.KEY_PLAN));
int ID = cursor.getInt(cursor.getColumnIndex(ModelHelper.KEY_ID_QUESTION));
inte.putExtra("Question", quest);
inte.putExtra("answ", repA);
inte.putExtra("ID", ID);
inte.putExtra("pos", pos);
inte.putExtra("position", i);
inte.putExtra("matr", matr);
Toast.makeText(new.this, "" + ID, Toast.LENGTH_SHORT).show();
startActivity(inte);
}
}
});
答案是在另一个活动中选择的,在第一个活动中我只有问题列表。 谢谢。
【问题讨论】:
标签: java android listview background-color