我使用Base Adapter来填充ListView,当我从列表中删除一个项目并调用adapter.notifyDataSetChanged时,它总是删除最后一个View。当我从其他帖子中读取时,它不是删除最后一个视图而是隐藏了最后一个视图,因为列表的数量减少了1。 任何人都可以帮我显示所需内容。
这是我的适配器类
public class ListOfFav extends BaseAdapter {
TextView qid,ques,category;
ArrayList<HashMap<String,String>> flightArray=new ArrayList<HashMap<String,String>>();
private static final String TAG_QID = "qid";
private static final String TAG_QUES = "question";
private static final String TAG_CAT= "category";
Context context;
ListOfFav() {
}
public ListOfFav(ArrayList<HashMap<String,String>> flightList,Context c){
Log.v("Constructor", String.valueOf(flightArray.size()));
flightArray=flightList;
context=c;
}
public int getCount() {
// TODO Auto-generated method stub
return flightArray.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row;
if(convertView==null||convertView.getTag()==null)
row = inflater.inflate(R.layout.list_questions_main, parent, false);
else
row=convertView;
qid=(TextView)row.findViewById(R.id.tQid);
ques= (TextView) row.findViewById(R.id.tQuestion);
category = (TextView) row.findViewById(R.id.tCategory);
qid.setText(flightArray.get(position).get(TAG_QID));
ques.setText(flightArray.get(position).get(TAG_QUES));
category.setText(flightArray.get(position).get(TAG_CAT));
return (row);
}
}
我将其更新为:
for (HashMap<String, String> map : FavoriteList) {
if (map.get(TAG_QID).equals(t.getText().toString()))
{
FavoriteList.remove(i);
favAdapter.notifyDataSetChanged();
break;
}
i++;
}
答案 0 :(得分:0)
我通过调用FavouriteListView.setAdapter(favAdapter)解决了这个问题后通知数组适配器已经更改了与之关联的列表,即刷新了列表视图适配器。