【问题标题】:Android - Custom ListsAndroid - 自定义列表
【发布时间】:2012-01-20 17:49:05
【问题描述】:

我不确定我们如何自定义列表是 android 2.2 或更高版本

我想要一个可以通过布局充气器制作自定义列表的基本活动

任何帮助将不胜感激!

【问题讨论】:

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

标签: android custom-lists


【解决方案1】:

我不确定这是否是您想要的,所以,这里有一个关于如何显示列表对话框的示例:

/* 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' 对象提供了其他方式来显示项目列表,允许您在没有单选按钮的情况下显示项目,在对话框上创建一些按钮等等。只需使用对象的方法来查看差异。

【讨论】:

  • 不,对不起,我不想要一个使用我自己布局的列表!
猜你喜欢
  • 2013-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多