Android : Android Items not added to listview

on Saturday, December 13, 2014


Im trying to getAll strings from a SharedPreferences file with particular keys.


Here is my code



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);
}

}


The line:



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


is causing the problem. The result of this is an empty ListView. Ideas?


Here is how the strings are saved to the shared preferences:



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


and currentList is a string whos value is determined by an item clicked in a different listview.


0 comments:

Post a Comment