1

プログラムで入力したい複数選択リストを使用してカスタム設定を作成しようとしています。以下に示すようにカスタム DialogPreference を作成しようとし、AlertDialog ビルダーを使用してダイアログを作成しました。問題は、さまざまなチュートリアルをつなぎ合わせて、ビューを返す必要がある onCreateDialogView() を実装/オーバーライドしていることです。AlertDialog.Builder を取得してビューを返すことができるかどうかはわかりません。

public class notifyPreferances extends DialogPreference {

//Tag used for logcat
String TAG = "notifyPreferances";

//Store values to diplay in mutliselect list
CharSequence[] selections;

//Constructor
notifyPreferances(Context context, AttributeSet attrs, CharSequence[] options) {
    super(context, attrs);
    setPersistent(false);
    selections = options;

}


@Override
protected View onCreateDialogView() {

    //Initialize Builer
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

    //Set Dialog Title
    builder.setTitle("Lights/Groups")

    //Set the items for the list and the onclick actions
    builder.setItems(selections, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            Log.i(TAG, "Selected Option: " + selections[item]);
        }
    });

    return builder.create(); 

    return super.onCreateDialogView();


}

@Override
protected void onDialogClosed(boolean positiveResult) {
    super.onDialogClosed(positiveResult);
}
}

この問題を解決する方法についての考えや推奨事項は、ビルダーをビューとして返すか、プログラムでダイアログを作成する別の方法のいずれかです。

ここに私が結合しようとしている 2 つのチュートリアルがあります: Concise way of writing new DialogPreference classes? および Android: AlertDialog 内の複数選択 ListView でアイテムを選択する

4

0 に答える 0