带有字符串的Android NumberPicker [英] Android NumberPicker with strings
本文介绍了带有字符串的Android NumberPicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已自定义NumberPicker以显示文本.输出是这样的:
I have customised the NumberPicker to show text. The output is this:
当我按OK时,我想将e.x鼠标添加到我的列表"Article"中.相反,我得到的是索引值(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文