如何将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,你有答案吗? –