Android Open Source - sdl_tester_android Base Single 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;
/*from   w ww . jav a 2  s.  c  o  m*/
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;

 * A generic, abstract class representing a ListView dialog that allows the user to select
 * a single listview item.  The selected item is returned to the listener as a generic object.
 * @author Mike Burke
 * @param <E>
public abstract class BaseSingleListViewDialog<E> extends BaseAlertDialog {

  // since this class is abstract, we'll keep these variables protected so subclasses can access them directly
  protected ListView listView;
  protected ArrayAdapter<E> adapter;
  protected E selectedItem;
  public BaseSingleListViewDialog(Context context, String title, List<E> items) {
    super(context, title, R.layout.listview);
    adapter = new ArrayAdapter<E>(context, android.R.layout.simple_list_item_1, 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) {
        selectedItem = ((ArrayAdapter<E>) parent.getAdapter()).getItem(position);


Java Source Code List