我可以调用多个适配器类android系统中的ListView? [英] Can I call Multiple adapter classes in android ListView?
问题描述
XML code
<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文件
My .java file
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();
}
}
在上面的code我已经使用警告对话框,显示客户名单
但我也想打电话给CustomListenerAdapter在同一
DialogBox的显示的字母索引快速滚动我可以叫2适配器类
在CUSTLIST结果
如果没有的话,请给我其他选项来显示字母索引
对于列表对话框中显示视图(弹出)
In the above code i have used Alert Dialog which shows List of customers
but i also want to call CustomListenerAdapter in same
dialogbox to show alphabetical indexer for fast scroll can i call 2 adapter classes
on "CustList"
if not then please give me other options to show alphabetical indexer
for list view shown in dialog box (popup)
(在这里你可以看到它 https://github.com/andraskindler/quickscroll 想法。 ..
要为列表视图对话框工作)
(here you can see idea for it https://github.com/andraskindler/quickscroll ... want to work for list view dialog box)
推荐答案
是的,你可以使用多个适配器的ListView如果
Yes you can use Multiple Adapter for ListView if,
- 如果你不与在同一时间两个适配器填充您的ListView控件。
- 如果您交替使用适配器填充您的ListView控件那么它的罚款。
- 如果一个适配器没有影响其他的只有一个适配器将生效的时间。
我觉得你的情况,你都显示在同一活动的ListView都因此其最好使用一个单独的适配器
I think in your case you are showing both ListView at the same Activity so its better to use a seperate Adapter
这篇关于我可以调用多个适配器类android系统中的ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!