Multiple EditText inside EditTextPreference

As the title says, I wonder if it is possible to have more than one EditText inside an EditText and save the contents of these EditText fields in separate “keys” inside a SharedPreference

enter image description here

+4
source share
2 answers

Yes it is possible. Hope this gives you an idea:

  LayoutInflater factory = LayoutInflater.from(OptionList.this); final View textEntryView = factory.inflate(R.layout.newgroup, null); AlertDialog.Builder alert = new AlertDialog.Builder(OptionList.this); alert.setTitle("Add Group"); alert.setMessage("Enter Group Name"); // Set an EditText view to get user input alert.setView(textEntryView); AlertDialog loginPrompt = alert.create(); final EditText input1 = (EditText) textEntryView.findViewById(R.id.et1); final EditText input2 = (EditText) textEntryView.findViewById(R.id.et2); alert.setPositiveButton("Create", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //Logic Here }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); } 
+2
source

I assume you can only call onAddEditTextToDialogView only once? An easy way would be to try to call it twice. However, it can simply overwrite what you already have. The documentation does not indicate what happens when this method is called multiple times.

EditTextPreference comes from the DialogPreference dialog. You can create your own DialogPreference dialog with several TextFields, and when you click OK, save them with the appropriate settings. It has to be the way to go.

Inside EditTextPreference there is also onBindDialogView (View). You can get away from trying to add your second EditText here, but this can be problematic. The last resort.

+3
source

All Articles