我正在尝试开发一个应用程序,你会说出一个名字,它会查找你的联系人并返回所有名字,如"Lars A.,Lars B.,Lars C.".我将所有这些名称保存在ArrayList中并且它可以正常工作.现在我想要一个AlertDialog,因此用户可以从此列表中选择正确的联系人.我想出来,它必须是一个CharSequence,所以我之前转换它.但我认为列表是空的,因为我只看到警报消息.
这个网站描述得很好,但使用静态值,我需要动态值:Android Developer Site.
继承我的代码:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
CharSequence[] cs = namearray.toArray(new CharSequence[namearray.size()]);
builder.setMessage("Welche/n " + cname + " meinst du?");
builder.setItems(cs, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int item) {
//do something
} });
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud) 我想缩短我的代码,但我被卡住了。我有一个测验,每个问题的答案都已加载。但我想要一个变量来为我做这件事。
这是代码:
if (nr === 1) {
$('#questionmobile').html(content.inst3.question1);
$('#answer1').html(content.inst3.q1a1);
$('#answer2').html(content.inst3.q1a2);
$('#answer3').html(content.inst3.q1a3);
$('#answer4').html(content.inst3.q1a4);
} else if (nr === 2) {
$('#questionmobile').html(content.inst3.question2);
$('#answer1').html(content.inst3.q2a1);
$('#answer2').html(content.inst3.q2a2);
$('#answer3').html(content.inst3.q2a3);
$('#answer4').html(content.inst3.q2a4);
}......
Run Code Online (Sandbox Code Playgroud)
如您所见,它非常多余,所以我想包括包含问题数量信息的变量“nr”。所以我想要这样的东西:
$('#questionmobile').html(content.inst3.question+nr);
$('#answer1').html(content.inst3.q+nr+a1);
Run Code Online (Sandbox Code Playgroud)
串联+nr+
不起作用,因为它没有指向正确的 JSON 内容。