【发布时间】:2017-05-05 20:13:13
【问题描述】:
我在 Android 的 SolutionActivity 类中有一个列表视图。适配器根据用户在另一个活动中输入的结果用元素填充列表。列表视图只能有两个值,“真”或“假”。我在整个网络上进行了搜索,我看到在自定义适配器类中调用了很多“getView”方法,但是我试图实现它,但我做不到弄清楚怎么做?我是为我的适配器创建一个单独的类吗?或者我可以将它添加到我的 SolutionActivity 的末尾吗?以及如何使用 getView 方法?无论如何这是我的代码...
public void setUserResults() { //displays the bit combination and users services in the listviews
ListView serviceNames = (ListView) findViewById(R.id.listofservices);
ListView bitResults = (ListView) findViewById(R.id.bitresults);
UserInputSet userInputSet = UserInputSet.getInstance();
List<String> userServices = MainActivity.dimensions;
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
userServices);
ArrayAdapter<Boolean> bitArrayAdapter = new ArrayAdapter<Boolean>(this, android.R.layout.simple_list_item_1,
CustomUseCase.getBestComboArray());
serviceNames.setAdapter(arrayAdapter);
bitResults.setAdapter(bitArrayAdapter);
}
如果“getBestComboArray()”的值为真,我想将行设置为绿色,如果为假,则设置为红色。任何人都可以提出一个好的解决方案吗?谢谢
【问题讨论】:
-
您必须为此使用自定义适配器
-
@AliAhsan 是的,我知道,我只是不知道如何像我在问题中所说的那样实现它。
-
好的,让我在答案中添加代码
标签: java android arrays listview android-arrayadapter