我在Android的SolutionActivity類中有一個listview。適配器使用基於用戶在其他活動中輸入的結果的元素填充列表。 listview只能有兩個值,「true」或者「false」。我在網上搜索了很多'getView'方法,在自定義的適配器類中調用,但是我試圖實現這個,但是我不能弄清楚如何?難道我創建一個獨立的類,只是爲了我的適配器?或者,我可以在我的SolutionActivity的末尾添加呢?我如何使用getView方法?反正這是我的代碼...如何根據每行上的內容更改ListView中某一行的顏色?
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()」的值是true,否則紅色如果是假的。任何人都可以提出一個很好的解決了這個?謝謝
你必須使用自定義適配器 –
@AliAhsan你知道,我只是不知道如何實現它,就像我在問題中所說的那樣。 –
好的,讓我在回答中添加代碼 –