2012-01-20 86 views
-3

我不知道該怎麼辦,我們的自定義列表是Android 2.2或以後的任何Android的 - 自定義列表

我想一個基本的活動,可以通過佈局吹氣使自定義列表

任何幫助,將不勝感激!

+4

「make custom lists」,呵呵?謹慎擴展? –

+1

你是什麼意思的自定義列表?是它你想創建一個自定義列表視圖或自定義適配器來顯示列表視圖。你能詳細說明你的需求嗎? – AD14

+0

它是一個自定義列表視圖,其中你可以添加元素?或者你的意思是一個適配器?plese指定...編輯問題 – subrussn90

回答

0

我不知道這是否是你想要的東西,所以,這裏就如何顯示一個列表對話框中的一個例子:

/* create the dialog */ 
final AlertDialog.Builder dlg = new AlertDialog.Builder(this); 

/* create the list of items to show on listbox */ 
String [] myList = {"A","B","C","D","E"}; 

/* create an adapter to control how the listbox should appear */ 
final ArrayAdapter<String> adapter = new ArrayAdapter<String> 
    (this,android.R.layout.select_dialog_singlechoice,myList); 

/* the item that will be initially selected on listbox */ 
int selected = 0; 

/* inform the dialog about our items and create an onClick function to listen for 
    user inputs */ 
dlg.setSingleChoiceItems(adapter,selected, 
    new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 
     // selected item is myList[which]; 
     dialog.dismiss(); 
    } 
    }); 

/* change the dialog title */ 
dlg.setTitle("My dialog"); 

/* show the dialog */ 
dlg.show(); 

這將顯示與單選按鈕一個對話框,用戶選擇一個其中。當用戶點擊該項目時,將會調用onClick函數。所選項目由'which'參數指向。 'dlg'對象提供了顯示項目列表的其他方式,允許您顯示沒有單選按鈕的項目,在對話框上創建一些按鈕以及類似的東西。只需使用對象的方法來查看差異。

+0

沒有對不起,我不希望我想要一個使用我自己的佈局的列表! –