-3

Android 2.2以降でリストをカスタムする方法がわかりません

レイアウトインフレータでカスタムリストを作れる基本アクティビティが欲しい

どんな助けでも大歓迎です!

4

1 に答える 1

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」オブジェクトは、アイテムのリストを表示する他の方法を提供します。これにより、ラジオ ボタンなしでアイテムを表示したり、ダイアログにいくつかのボタンを作成したりできます。オブジェクトのメソッドをいじって、違いを確認してください。

于 2012-01-20T18:27:29.553 に答える