在我的应用程序中,我应该从服务器获得一些list
,我应该显示此列表。
代码:
private String[] mostlyMatchedKeywordsStrings;
mostlyMatchedKeywordsStrings = searchResponse.getData().getMostlyMatchedKeywordsText();
cloudChipList.clear();
fullSearchMini_chipCloud.removeAllViews();
for (int i = 0; i < mostlyMatchedKeywordsStrings.length; i++) {
cloudChipList.add(mostlyMatchedKeywordsStrings[i]);
if (i >= mostlyMatchedKeywordsStrings.length - 2) {
fullSearchMini_didYouMeanLay.setVisibility(View.VISIBLE);
fullSearchMini_chipCloud.addChip(mostlyMatchedKeywordsStrings[i]);
Log.e("searchKeys", mostlyMatchedKeywordsStrings[i]);
fullSearchMini_chipCloud.setChipListener(new ChipListener() {
@Override
public void chipSelected(int i) {
try {
Log.e("searchKeys", "new : " + mostlyMatchedKeywordsStrings[i]);
}
catch (Exception e) {
}
}
@Override
public void chipDeselected(int i) {
}
});
}
}
向用户显示此数据时,它是否正确并显示数据,但点击此项目时会显示另一项!
在Logcat中显示以下项目:
searchKeys: Recep Ivedik 5
但是当点击这个项目时,我会在logcat中显示另一个项目:
searchKeys: new : Recep Ivedik 3
对于显示项目并单击我使用此代码mostlyMatchedKeywordsStrings[i]
,为什么在logCat中显示单击此项目时的其他项目?!
答案 0 :(得分:1)
试试这个:
如果阻止,则将以下行移到内部:
cloudChipList.add(mostlyMatchedKeywordsStrings[i]);
然后在方法onChipSelected()
中使用:
Log.e("searchKeys", "new : " + cloudChipList.get(i));