我在dailog
片段中遇到問題。我想要json
數組到dailog
片段中,但我不知道如何去做,下面是我正在嘗試的。任何暗示?如何讓json數組進入對話框片段
public class MyAlertSortDialogFragmentIndividual extends DialogFragment {
public static final String DATA = "items";
public static final String SELECTED = "selected";
CharSequence[] cs;
ArrayList<User> transactionList = new ArrayList<>();
List <User> users;
String s;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
users=new ArrayList<>();
Bundle bundle = getArguments();
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
dialog.setTitle("Sort By");
dialog.setPositiveButton("Cancel", new PositiveButtonClickListener());
bundle.putSerializable("key", transactionList);
String str = bundle.getString("str");
users = new Gson().fromJson(str,ArrayList.class);
return dialog.create();
}
class PositiveButtonClickListener implements DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}
DialogInterface.OnClickListener selectItemListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// process
//which means position
dialog.dismiss();
}
};
我應該怎麼得到的模型類的數據。
告訴我你的STR值字符串str = bundle.getString( 「STR」) ;這一個 –
users = new Gson()。fromJson(str,ArrayList.class);在這一行中你必須設置在這個str中有實例的類名...................這裏,ArrayList.class錯誤的值 –
也可以在後面的代碼裏發送這個str值到MyAlertSortDialogFragmentIndividual這個片段 –