Android项目未添加到listview

时间:2014-12-13 23:29:02

标签: android listview sharedpreferences

我尝试使用特定键从SharedPreferences文件中获取所有字符串。

这是我的代码

private void updateListView() {
    final ListView lvCheckList = (ListView) findViewById(R.id.lvCheckList);
    Map<String,?> keys = checkListData.getAll();

    ArrayList<String> checkListStrings = new ArrayList<String>();
    for(Map.Entry<String,?> entry : keys.entrySet()){
         if (entry.getValue() instanceof String) {
         if (entry.getKey() == currentList + "ItemName") {
            checkListStrings.add((String) entry.getValue());
        }
         }

    ArrayAdapter<String> checkListArrayAdapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_1, checkListStrings );

    lvCheckList.setAdapter(checkListArrayAdapter); 
}

}

该行:

if (entry.getKey() == currentList + "ItemName") {

造成了这个问题。结果是一个空的ListView。想法?

以下是字符串保存到共享首选项的方式:

String checkListStringData = etItemName.getText().toString();
checkListData = getSharedPreferences(filename,0);
SharedPreferences.Editor checkListEditor = checkListData.edit();
checkListEditor.putString(checkListStringData + "ItemName", checkListStringData);
checkListEditor.commit();

和currentList是一个字符串,其值由在不同列表视图中单击的项确定。

0 个答案:

没有答案
相关问题