Android Open Source - sdl_tester_android Base Multiple List View Dialog

From Project

Back to project page sdl_tester_android.


The source code is released under:

Copyright (c) 2014, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are m...

If you think the Android project sdl_tester_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.livio.sdl.dialogs;
//  ww  w  . java 2 s  .  c o m
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.livio.sdl.R;
import com.livio.sdl.utils.AndroidUtils;

 * A generic, abstract class representing a ListView dialog that allows the user to select
 * multiple listview items.  Selected items are stored in a protected List<E> object
 * called selectedItems, which can be used by subclasses of this class.
 * @author Mike Burke
 * @param <E>
public abstract class BaseMultipleListViewDialog<E> extends BaseOkCancelDialog {

  protected ListView listView;
  protected List<E> selectedItems = new ArrayList<E>();
  public BaseMultipleListViewDialog(Context context, String title, List<E> items) {
    super(context, title, R.layout.listview);
    listView.setAdapter(AndroidUtils.createMultipleListViewAdapter(context, items));

  protected void findViews(View parent) {
    listView = (ListView) parent.findViewById(;
    listView.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        toggleItem(((ArrayAdapter<E>) parent.getAdapter()).getItem(position));
   * Toggles the input item in the list of selected items.  So, if the current item
   * was not selected, it is added to the list; if the current item was selected,
   * it is removed from the list.
   * @param item
  protected void toggleItem(E item){
    final boolean alreadyInList = selectedItems.contains(item);


Java Source Code List