Java Android对话框如何从自定义适配器对话框获取文本
有没有办法使用这个代码?但是根据我的研究,我选择的只能实现到listview和spinner。。但在我的例子中,如何在自定义警报对话框适配器中使用它Java Android对话框如何从自定义适配器对话框获取文本,java,android,android-alertdialog,Java,Android,Android Alertdialog,有没有办法使用这个代码?但是根据我的研究,我选择的只能实现到listview和spinner。。但在我的例子中,如何在自定义警报对话框适配器中使用它 this is my code in my adapter.. the int which indicates the id of the item, but how can i get the text value of the item? i want to display it to my button after selecting the
this is my code in my adapter.. the int which indicates the id of the item, but how can i get the text value of the item? i want to display it to my button after selecting the item from the dialog..
builder.setSingleChoiceItems(adapter,-1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 0:
}
dialog.dismiss();
}
});
@覆盖
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
//关于选择微调器项
String label=parent.getItemAtPosition(position.toString();
//显示所选微调器项
Toast.makeText(parent.getContext(),“您选择:”+标签,Toast.LENGTH_LONG.show();
}
我通过将其添加到代码中来解决这个问题
my adapter变量由ArrayAdapter adapter=new ArrayAdapter
通过添加
该变量对应于该项在对话框中的ID位置,使用adapter.getItem()它可以调用该项的字符串值,因此我将其显示到我的按钮
你是说你已经找到解决办法了?如果是,请将解决方案作为答案发布。不要质疑它本身。并将其标记为已接受。否则会有点混乱,我明白了。事实上,这是我第一次回答自己的问题。谢谢你的提醒o问题..并将其标记为已接受:)接受我自己的答案需要两天时间:o:)好的..两天后接受它然后:接受你的答案。:)
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// On selecting a spinner item
String label = parent.getItemAtPosition(position).toString();
// Showing selected spinner item
Toast.makeText(parent.getContext(), "You selected: " + label, Toast.LENGTH_LONG).show();
}
builder.setSingleChoiceItems(adapter,-1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String itemName=adapter.getItem(which);
button.setText(itemName);
dialog.dismiss();
}
});
String itemName=adapter.getItem(which);
button.setText(itemName);