前提・実現したいこと
onCreateDialogを使用したDiaLogにて
setMultiChoiceItemsを利用したチェックボックスを表示されない問題を解決したい。
目標としている画像
https://gyazo.com/a1b09d3c6f52f5724a5615cd7379205c
このチェックボックスのみ表示されてない状態です
現在問題となっている画像
https://gyazo.com/6a8e945f6b89c0354784cb86c2f5c4bb
発生している問題・エラーメッセージ
無し
該当のソースコード
AddTaskDiaLogFragment.java
java
1 2public class AddTaskDialogFragment extends DialogFragment { 3 4中略 5 6 7 @NonNull 8 @Override 9 public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { 10 11 CharSequence[] items = {"重要","test","aaa"}; 12 boolean[] itemChecked = new boolean[items.length]; 13 14 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 15 16 //ダイアログのレイアウトを適用 17 LayoutInflater inflater = requireActivity().getLayoutInflater(); 18 builder.setView(inflater.inflate(R.layout.add_task_dialog, null)); 19 20 builder.setMessage("タスクの追加") 21 22 23・・・・・・・・問題箇所・・・・・・・・・・・・・・・・・・・・ 24 .setMultiChoiceItems(items, itemChecked, new DialogInterface.OnMultiChoiceClickListener() { 25 @Override 26 public void onClick(DialogInterface dialog, int which, boolean isChecked) { 27 28 } 29 }) 30・・・・・・・・問題箇所・・・・・・・・・・・・・・・・・・・・ 31 32 33 34 .setPositiveButton("OK",new DialogInterface.OnClickListener(){ 35 public void onClick(DialogInterface dialog,int id){ 36 EditText editText = (EditText) getDialog().findViewById(R.id.task_text); 37 if (editText != null) { 38 //タスク追加処理 39 disposable.add(taskModel.insertTask(editText.getText().toString()) 40 .subscribeOn(Schedulers.io()) 41 .observeOn(AndroidSchedulers.mainThread()) 42 .subscribe(() -> {}, 43 throwable -> Log.e(TAG, "Unable to update username", throwable))); 44 } else { 45 //例外 46 Log.e("", "EditText not found!"); 47 } 48 } 49 }) 50 .setNegativeButton("キャンセル", new DialogInterface.OnClickListener() { 51 @Override 52 public void onClick(DialogInterface dialog, int id) { 53 //user cancelled the dialog 54 } 55 }); 56 57 return builder.create(); 58 59 } 60}
add_task_dialog.xml
xml
1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" 4 android:layout_width="wrap_content" 5 android:layout_height="wrap_content"> 6 7 <EditText 8 android:id="@+id/task_text" 9 android:inputType="text" 10 android:layout_width="match_parent" 11 android:layout_height="wrap_content" 12 android:layout_marginTop="16dp" 13 android:layout_marginLeft="4dp" 14 android:layout_marginRight="4dp" 15 android:layout_marginBottom="4dp" /> 16 17 18</LinearLayout>
試したこと
”チェックボックス 表示されない”などの形で調べてもうまく出てこないためどのような調べ方から進めればよいかわからないです。
本来表示したい形はチェックボックス一つのみですが
setMultiChoiceItems自体が複数表示する用のメソッドなので一旦複数表示される形で変数を用意するも効果なし
補足情報(FW/ツールのバージョンなど)
Windows10 AndroidStudio java

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/03/04 00:10