English 中文(简体)
从清单中删除有定制改编器的物品
原标题:Remove items from ListView with a custom adapter

我有一个惯例<代码>ListView和改编者。 我可以删除我的习惯名单上所列清单中的项目,但我可以删除<代码>ListView。 当我试图打电话adapter.remove(position)时,编辑们说,“将一种方法“remove(int status)”。 我不知道,当我把这种方法引入适应者时,我应该做些什么。 法典:

www.un.org/spanish/ecosoc

lv = (ListView) findViewById(R.id.list);
        LayoutInflater mLInflater = getLayoutInflater();
        final ListViewAdapter adapter = new ListViewAdapter(
                getApplicationContext(), kimdenlist, konulist,
                mLInflater);
        lv.setAdapter(adapter);

www.un.org/spanish/ecosoc 清单:

public class ListViewAdapter extends BaseAdapter {
    static HashMap<Integer, Boolean> cartItems = new HashMap<Integer, Boolean>();
    Context mContext;
    ArrayList<String> kimdenlist; // to load images
    ArrayList<String> konulist; // for data
    LayoutInflater mLayoutInflater;

    public ListViewAdapter(Context context, ArrayList<String> kimdenlist, ArrayList<String> konulist,
            LayoutInflater layoutInflater) {
        mContext = context;
        this.kimdenlist = kimdenlist;
        this.konulist = konulist;
        mLayoutInflater = layoutInflater;
    }

    @Override
    public int getCount() 
    {

        return kimdenlist.size(); // images array length
    }

    @Override
    public Object getItem(int arg0) {

        return null;
    }

    @Override
    public long getItemId(int arg0) {

        return 0;
    }

    int count = 0;

    // customized Listview
    @Override
    public View getView(int position, View arg1, ViewGroup arg2) {

        View v;
        final int pos = position;
        v = mLayoutInflater.inflate(R.layout.listust, null);

        TextView kimden = (TextView) v.findViewById(R.id.textvKimden);
        kimden.setText(kimdenlist.get(position));
        TextView konu = (TextView) v.findViewById(R.id.textvKonu);
        konu.setText(konulist.get(position));
        CheckBox ch = (CheckBox) v.findViewById(R.id.chk);
        try {
            if (count != 0) {
                boolean b = cartItems.get(pos);
                if (b == false)
                    ch.setChecked(false);
                else
                    ch.setChecked(true);
            }
        } catch (NullPointerException e) {

        }


        ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                cartItems.put(pos, arg1);
                count++;

            }
        });
        return v;
    }

    public static HashMap<Integer, Boolean> getcartItems() {
        return cartItems;
    }

}

www.un.org/spanish/ecosoc 当我点击“delete_Button”时: 我只能从名单上删除:。

konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
问题回答

这是因为你的名单上没有删除方法! 你们延伸了基地Adapter,没有拆除方法。 你的住所在名单Adapter中制造了去除方法,它会像样。

public void remove(int position){
    konulist.remove(konulist.get(position));;
    kimdenlist.remove(kimdenlist.get(position));
}

你们必须了解清单如何看待和适应工作。 改编者拥有清单调查数据。 当要建立名单线时,就要求采用调制方法。 清单规模按适应者CapCount(......)的回报值计算。

从BUT NOTINSIDE ADAPTER CLASS名单上删除一个项目:

lv.removeViewAt(index);
adapter.notifyDataSetChanged();

如果“指数”具体指明了保留该项目的“名单”中的位置或指数。

To remove an item from ListView INSIDE ADAPTER CLASS: First you need to add a Tag to each item in the list. use some layout within the content item in the list to assign that Tag. This can be done within the method getView ().

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    row = convertView;

    if(row == null){
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.item_lista_lugares_visitar, parent, false);
        holder = new ViewHolder();

        // ... DO WHAT YOU NEED HERE
        holder.linearLayoutContainer = (LinearLayout) row.findViewById(R.id.ll_container);
        // Set the position as a Tag for the view
        holder.linearLayoutContainer.setTag(position);

    } else {
        holder = (ViewHolder) row.getTag();
    }

    // ... DO WHAT YOU NEED HERE

    return row;
}

// Method for remove an item of ListView inside adapter class
// you need to pass as an argument the tag you added to the layout of your choice
public void removeView(Object position) {
      // lv and the adapter must be public-static in their Activity Class
      SomeActivity.lv.removeViewAt(Integer.parteInt(position).toString());
      SomeActivity.adapter.notifyDataSetChanged();
}

之后

konulist.remove(konulist.get(position)); kimdenlist.remove(kimdenlist.get(position));

您可以称之为:





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签