gpt4 book ai didi

java - 如何在警报对话框中保存多选状态?

转载 作者:行者123 更新时间:2023-12-01 16:23:14 24 4
gpt4 key购买 nike

我有一个代码,我创建了一个方法来显示带有多选选项的对话框,但是当检查并单击“确定”按钮时,状态未保存,我该怎么做?我看到了一些带有共享首选项的内容,但我无法在我的代码中实现它,有人可以帮助我吗?

 public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {

final View view = inflater.inflate(R.layout.fragment_inseticida, container, false);


gps = view.findViewById(R.id.imageButton);
gps.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAlertDialog();
}
});



private void showAlertDialog (){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Habilitar GPS");

String[] Gps = new String[]{
"Habilitar GPS",

};

// Boolean array for initial selected items
final boolean[] checkedgps = new boolean[]{
true, // GPS

};

// Convert the color array to list
final List<String> gpsList = Arrays.asList(Gps);

builder.setMultiChoiceItems(Gps, checkedgps, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i, boolean b) {


checkedgps[i] = b;

String CurrentItem = gpsList.get(i);

Toast.makeText(getActivity(),CurrentItem + " " + b,Toast.LENGTH_SHORT).show();



}
});
builder.setCancelable(false);

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

}
});

AlertDialog dialog = builder.create();
// Display the alert dialog on interface
dialog.show();

}

最佳答案

检查this所以回答。

使用loadArray检索final boolean[]checkedgps中最初的数据以及 storeArraypublic void onClick(...)

中按下时保存数据

关于java - 如何在警报对话框中保存多选状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62214150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com