如何將AlertDialog
- multipleChoiceItems
中的項存儲在一個變量中。還有一個分隔符,
。我需要它以傳遞到遠程服務器並使用php
- explode
函數將其解壓縮。AlertDialog多項存儲在一個變量中帶有分隔符
這裏是我的演示代碼: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,你有答案嗎? –