Android-自定义列表

Android-自定义列表,android,custom-lists,Android,Custom Lists,我不确定我们如何在android 2.2或更高版本中定制列表 我想要一个基本的活动,可以使布局充气自定义列表 任何帮助都将不胜感激 我不确定这是否是您想要的,因此,下面是一个如何显示列表对话框的示例: /* create the dialog */ final AlertDialog.Builder dlg = new AlertDialog.Builder(this); /* create the list of items to show on listbox */ String [] m

我不确定我们如何在android 2.2或更高版本中定制列表

我想要一个基本的活动,可以使布局充气自定义列表


任何帮助都将不胜感激

我不确定这是否是您想要的,因此,下面是一个如何显示列表对话框的示例:

/* 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();
/*创建对话框*/
final AlertDialog.Builder dlg=新建AlertDialog.Builder(此);
/*创建要在列表框上显示的项目列表*/
字符串[]myList={“A”、“B”、“C”、“D”、“E”};
/*创建适配器以控制列表框的显示方式*/
最终ArrayAdapter适配器=新的ArrayAdapter
(这是android.R.layout.select\u dialog\u singlechoice,myList);
/*最初将在列表框中选择的项目*/
选定的整数=0;
/*通知对话框我们的项目,并创建一个onClick函数来监听
用户输入*/
dlg.设置SingleChoiceItems(适配器,选定,
新建DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
//所选项目为myList[其中];
dialog.dismise();
}
});
/*更改对话框标题*/
dlg.setTitle(“我的对话框”);
/*显示对话框*/
dlg.show();

这将显示一个带有单选按钮的对话框,供用户选择其中一个按钮。当用户单击项目时,将调用onClick函数。所选项目由“which”参数指向。“dlg”对象提供了显示项目列表的其他方式,允许您在不使用单选按钮的情况下显示项目、在对话框上创建一些按钮以及类似的内容。只需使用object的方法即可查看差异。

“创建自定义列表”,是吗?想扩展吗?自定义列表是什么意思?是否要创建自定义listview或自定义适配器来显示listview。你能详细说明一下你需要什么吗?这是一个自定义的列表视图,你可以在其中添加元素吗?或者你是指一个适配器吗?请指定…编辑问题我有一个我想在列表中使用的布局,或者换句话说,我不想使用LayoutFlater!不,对不起,我不想要我想要一个使用我自己布局的列表!