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;
/*fromwww.java2s.com*/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>
*/publicabstractclass 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);
listView.setAdapter(adapter);
}
@Override
protectedvoid findViews(View parent) {
listView = (ListView) parent.findViewById(R.id.listView);
listView.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings("unchecked")
@Override
publicvoid onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectedItem = ((ArrayAdapter<E>) parent.getAdapter()).getItem(position);
notifyListener(selectedItem);
dismiss();
}
});
}
}