本文介绍了带字符串的 Android NumberPicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已自定义 NumberPicker 以显示文本.输出是这样的:
I have customised the NumberPicker to show text. The output is this:
当我按下 OK 我想将 e.x 鼠标添加到我的列表文章"中.我得到的是索引值 (int).
when I press OK I want to add the e.x mouse to my list "Article". What I'm getting instead is the index value (int).
它由array[]"填充,它包括一个显示数据的列表.获取我的项目/字符串的解决方法是什么?
Its populated by "array[]", it includes a list with the data shown.What's the workaround to get my item/string.?
public void Generatortable(){
final android.support.v7.app.AlertDialog.Builder alert = new android.support.v7.app.AlertDialog.Builder(this);
alert.setCancelable(false);
LinearLayout l1 = new LinearLayout(getApplicationContext());
l1.setOrientation(LinearLayout.HORIZONTAL);
final NumberPicker artikkler = new NumberPicker(this);
String array[] = new String[responseList.size()];
for(int j =0;j<responseList.size();j++){
array[j] = responseList.get(j);
}
artikkler.setMaxValue(responseList.size() - 1);
artikkler.setMinValue(0);
artikkler.setDisplayedValues(array);
artikkler.setWrapSelectorWheel(true);
l1.addView(artikkler);
alert.setView(l1);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Article.add(String.valueOf(artikkler.getValue()));
lviewAdapter.notifyDataSetChanged();
lview.setAdapter(lviewAdapter);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
}
推荐答案
换行
Article.add(String.valueOf(artikkler.getValue()));
来自
Article.add(responseList.get(artikkler.getValue());
这篇关于带字符串的 Android NumberPicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!