Reputation: 11
whenever I add a new value in an array it creates two rows with one empty row in listview. when i delete a value in array the value is removed but both row still exists.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listcontact); sharedPreferences=getSharedPreferences(preferences,Context.MODE_PRIVATE);
for(int i=1;i<=n+1;i++) {
String st=sharedPreferences.getString(String.valueOf(i), "");
conact_list.add(st);
}
ArrayAdapter adapter=new ArrayAdapter<String>(getBaseContext(),android.R.layout.simple_list_item_1,conact_list);
ListView cv= (ListView) findViewById(R.id.listview);
cv.setAdapter(adapter);
}
I have checked arraylist and arrayadapter both doesnt have empty value or extra size but in list view it displays as follow :
Log:
04-25 12:40:31.491 30892-30892/com.symbols.syedibrahim.phonetrack D/ERR﹕ entered 04-25 12:40:31.501 30892-30892/com.symbols.syedibrahim.phonetrack D/ERR﹕ + 04-25 12:40:31.501 30892-30892/com.symbols.syedibrahim.phonetrack D/ERR﹕ +93838394 04-25 12:40:31.501 30892-30892/com.symbols.syedibrahim.phonetrack D/ERR﹕ +947574748 04-25 12:40:31.501 30892-30892/com.symbols.syedibrahim.phonetrack D/ERR﹕ +87478494 04-25 12:40:31.501 30892-30892/com.symbols.syedibrahim.phonetrack D/ERR﹕ aA created[93838394, 947574748, 87478494] 04-25 12:40:31.501 30892-30892/com.symbols.syedibrahim.phonetrack D/ERR﹕ lv3count3list view count:0 04-25 12:40:31.501 30892-30892/com.symbols.syedibrahim.phonetrack D/ERR﹕ la
Upvotes: 0
Views: 697
Reputation: 3751
Below is my opinion:
Case 1: Check the number of data object is matching with your item in the view. It mean in for(int i=1;i<=n+1;i++
we check the value of n, does it equal to the number items displayed in the view.
If two values are same, you should check you data in preference again.
Otherwise, go to case 2 : check your adapter, in adapter you should check getView
and getCount
method. The number value returned by getCount
must be same with number of data object.
Upvotes: 1