问题描述
- 从一个警示框中点击获取值
-
程序中的警示框中有一个 channels 列表。
我想从 channels 点击中获取值。public void ShowChannelDialog(){ String[] channels = new String[_publicChannels.size()]; channels = _publicChannels.toArray(channels); AlertDialog.Builder showChannel = new AlertDialog.Builder(this); showChannel.setTitle("Channel List ("+(_publicChannels.size()-1)+" channels)"); showChannel.setItems(channels, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { _publicChannels.clear(); if (item == (_publicChannels.size())) { System.out.println("NEW CHANNEL"); CreateNewChannel(); dialog.dismiss(); }else{ String channel = String.valueOf(item); System.out.println("Selected: " + channel); } } });
String.valueof(item) 只在数组中给出一个int值,我想获取实际的text值。
如何实现?谢谢!
解决方案
String channel = channels[item];
解决方案二:
item 是int值 代表Item的positon
如上所说得channels[item]获取
时间: 2024-09-09 23:05:36