【问题标题】:color listview line with condition android/java带有条件 android/java 的颜色 listview 行
【发布时间】: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


    【解决方案1】:

    当您在列表视图中呈现项目时,根据您描述的逻辑设置背景颜色。

    【讨论】:

    • 如果我在选择我不能因为我在下一个活动中回答时这样做,那么我会使用 listView 回到活动
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2016-05-09
    • 2011-05-09
    • 2012-10-18
    • 2019-05-03
    • 2015-09-20
    相关资源
    最近更新 更多