notifyDataSetChanged 删除最后一个视图

notifyDataSetChanged removes last view

我使用 Base Adapter 来填充 ListView,当我从列表中删除一个项目并调用 adapter.notifyDataSetChanged 时,它总是删除最后一个视图。正如我从其他帖子中读到的那样,它可能没有删除最后一个视图,而是隐藏了最后一个视图,因为列表的数量减少了 1。 谁能帮我显示需要的内容

这是我的适配器class

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

我在通知数组适配器与其关联的列表已更改后调用 FavouriteListView.setAdapter(favAdapter) 解决了这个问题,即通过刷新列表视图适配器。