如何从适配器中删除带有图标的项目

时间:2013-01-23 17:41:42

标签: android android-listview adapter

我试图从适配器中删除带有适配器的项目(文本)的图标。 我知道它看起来像一个简单的任务而且我做了但仍然有一些错误。它看起来像我删除它们的项目很奇怪列表中的第一个图标和最后一个获得相同的图标。 这是代码:

ListRssLinkAndTitle=(ArrayList)dbAdpter.getWantedItemsList(this,"RssTitle","link","Rtl","image");//get wanted items from db 

        for (int j=0;j<ListRssLinkAndTitle.size();j++)
            listKeys.add(ListRssLinkAndTitle.get(j).title);

        for (int i=0;i<ListRssLinkAndTitle.size();i++)
            Icon.add(ListRssLinkAndTitle.get(i).icon);

        listAdapter = new ListRssAdpter(this, R.layout.titlesrss, listKeys,Icon);

            lv.setAdapter(listAdapter); 
            lv.setOnItemClickListener(new OnItemClickListener() 
            {

                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                        if  (0<dbAdpter.deleteRssItem(ListRssLinkAndTitle.get(position).title,ListRssLinkAndTitle.get(position).url))
                        {
                            ListRssLinkAndTitle.remove(position);
                            listAdapter.items.remove(position);
                            listAdapter.FavIconList.remove(position);


                listAdapter.notifyDataSetChanged();

                    }
                    else
                        Toast.makeText(getApplicationContext(),  getResources().getString(R.string.operationFaild),0).show();
                }
            } 

        });

和适配器:

public class ListRssAdpter extends ArrayAdapter {
    private Context mContext;
    private int id;
    public List<String> items;
    public List<byte[]> FavIconList;
    public boolean iconRemove=false;
    public int IconHigh=-1;// if -1 not in use

    //constractor for fav icon
    public ListRssAdpter(Context context, int textViewResourceId, List<String> list,List<byte[]> icon) {
        super(context, textViewResourceId, list);
        mContext = context;
        id = textViewResourceId;
        items = list;
        this.FavIconList=icon;
    }

public View getView(int position, View v, ViewGroup parent) {
        View mView = v;
        if (mView==null) {
            LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mView = vi.inflate(id, null);

        }
        ImageView   removeIcon = (ImageView)mView.findViewById(R.id.iconremove); 
        ImageView   favIcon = (ImageView)mView.findViewById(R.id.iconfav); 
        if (iconRemove)
        {
            removeIcon.setVisibility(View.VISIBLE);
            favIcon.setVisibility(favIcon.GONE);
        }
        else 
        {
            if (FavIconList.get(position)!=null)
            {
            Bitmap bitmap = BitmapFactory.decodeByteArray(FavIconList.get(position), 0, FavIconList.get(position).length);
            favIcon.setImageBitmap(bitmap);
            }
            else   BitmapFactory.decodeResource(mView.getContext().getResources(),R.drawable.rss);
            removeIcon.setVisibility(removeIcon.GONE);
            favIcon.setVisibility(favIcon.VISIBLE);
        }


        TextView tx = (TextView) mView.findViewById(R.id.textView);


        //if this view is on main screen
        if (tx == null) {
            tx = ((TextView) mView);
        }
        if (this.IconHigh!=-1)
            tx.setHeight(this.IconHigh);
        //this.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);

        tx.setText(items.get(position));
        return mView;

    }
}

如果您找不到逻辑错误,也许您可​​以给我一个简单的示例工作代码:)

0 个答案:

没有答案