Results 1 to 2 of 2
  1. #1

    How to add list view items to an array list? Oy any work arounds for below scenario?

    In the below code, where the itemís position and title is getting saved in list_items works fine if list_items and items are ArrayList. For ex;

    But I am trying to use listview:

    The problem exists on line # 10

    1. final Listadapter Adapter = new Listadapter(this,packageList1, packageManager);

    2. items.setAdapter(Adapter);

    3. items.setChoiceMode(apps.CHOICE_MODE_MULTIPLE_MODAL);
4. items.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

    5. @Override

    6.    public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
7.        count = count +1;
8.        mode.setTitle(count + "items selected");

    9.    //problem resides in the below line
10.   list_items.add(items.get(position));
11.    }

    In the above code, on selecting an item from listview I am trying to save it in an Arraylist i.e list_items which could be used in onActionItemClicked method for further action on that respective item.

    Any ideas on how to solve or find a workaround to use a listview in the above situation?

  2. #2
    I think this can help you
    public View getViewByPosition(int pos, ListView listView) {
    final int firstListItemPosition = listView.getFirstVisiblePosition();
    final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

    if (pos < firstListItemPosition || pos > lastListItemPosition ) {
    return listView.getAdapter().getView(pos, null, listView);
    } else {
    final int childIndex = pos - firstListItemPosition;
    return listView.getChildAt(childIndex);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts