Как хранить элементы с AlertDialog
- multipleChoiceItems
в одной переменной. Также с сепаратором ,
. Мне нужно это, чтобы перейти на удаленный сервер и извлечь его с помощью функции php
- explode
.AlertDialog Несколько предметов Store в одной переменной с разделителем
Вот мой демо-код: MainActivity.java
final RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);
Button btn = (Button) findViewById(R.id.btn);
final TextView tv = (TextView) findViewById(R.id.tv);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Build an AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
// String array for alert dialog multi choice items
String[] colors = new String[]{
"Red",
"Green",
"Blue",
"Purple",
"Olive"
};
// Boolean array for initial selected items
final boolean[] checkedColors = new boolean[]{
false, // Red
true, // Green
false, // Blue
true, // Purple
false // Olive
};
// Convert the color array to list
final List<String> colorsList = Arrays.asList(colors);`
builder.setMultiChoiceItems(colors, checkedColors, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// Update the current focused item's checked status
checkedColors[which] = isChecked;
// Get the current focused item
String currentItem = colorsList.get(which);
// Notify the current action
Toast.makeText(getApplicationContext(),
currentItem + " " + isChecked, Toast.LENGTH_SHORT).show();
}
});
Я хочу, чтобы сохранить выбранные элементы в currentItem
переменной.
Таким образом, выходной образец будет выглядеть следующим образом (в Logcat
): Red,Green,Blue,Purple
Привет @RoCk, пожалуйста, примите мой ответ, если он работает для вас. –
Здравствуйте, @RoCk, вы получили свой ответ? –