【发布时间】:2013-12-05 07:47:05
【问题描述】:
XML 代码
<ListView
android:id="@+id/listView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fastScrollEnabled="true"
android:fastScrollAlwaysVisible="true"
android:scrollbars="vertical"
android:fadingEdge="vertical"
android:cacheColorHint="#00000000">
</ListView>
我的 .java 文件
public class TestListView extends Activity{
private DatabaseConection db;
Button btn;
private List<Customer> custList = new ArrayList<Customer>();
private CustomListenerAdapter custListAdaptor;
private ListView list;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_listview);
// Connection object for Login
db= new DatabaseConection(this);
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(View v) {
createListViewDialog(btn);
}
});
try{
list = (ListView) findViewById(R.id.listView1);
// populate the store list
custList = db.getAllCustomers();
// create an adaptor with the store list
custListAdaptor = new CustomListenerAdapter(this,custList);
// assign the listview an adaptor
list.setAdapter(custListAdaptor);
}catch(Exception e){
e.getStackTrace();
}
}
// on button click i called dialog wich contains List (sorted)
public void createListViewDialog(final Button btnId) {
AlertDialog levelDialog = null;
// Creating and Building the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final ArrayAdapter<Customer> ad = new ArrayAdapter<Customer> (this,android.R.layout.simple_list_item_1,custList.toArray(new Customer[custList.size()]));
builder.setSingleChoiceItems(ad, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
btnId.setText(ad.getItem(item).toString());
}
});
levelDialog = builder.create();
levelDialog.show();
}
}
在上面的代码中,我使用了显示客户列表的警报对话框
但我也想在同一个中调用 CustomListenerAdapter
显示快速滚动的字母索引器的对话框我可以调用 2 个适配器类吗
关于“客户名单”
如果不是那么请给我其他选项来显示字母索引器
对于对话框中显示的列表视图(弹出)
(在这里你可以看到它的想法https://github.com/andraskindler/quickscroll ... 想为列表视图对话框工作)
【问题讨论】:
标签: java android listview dialog