动态填充的Andr​​oid微调 [英] Populate android spinner dynamically

查看:196
本文介绍了动态填充的Andr​​oid微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在像下面的code的Andr​​oid创造了一个文本视图:

I have created a Text View in android like the code below:

 LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        sv.addView(ll);

txtv = new TextView(this);
txtv.setText("text");
ll.addView(txtv);     

我创建了一个微调相同的:

Same way I have created a spinner:

spinner = new Spinner(this);
ll.addView(spinner);

但我不能就微调填充值。大多数教程给人填充微调与阵列适配器,但是它正在XML的ID,如R.id. ....因为我创建动态我不能做这样的方式。如何动态填充微调?

But I am unable to populate value on the spinner. Most tutorials giving populating spinner with array adapter but it is taking id of xml, like R.id. .... Since I am creating dynamic I cant do like that way. How can I populate spinner dynamically?

推荐答案

您需要创建SpinnerAdapter或BaseAdapter的impementation并将它设置为微调的适配器。

You need to create an impementation of SpinnerAdapter or BaseAdapter and set it as the adapter of the Spinner.

http://developer.android.com/reference/android/widget/ SpinnerAdapter.html

您可以通过从数组适配器返回的意见。

You return the views through the adapter from the array.

也请考虑重新命名变量。他们不是非常的描述和命名变量11做法不好。

Also please consider renaming your variables. They aren't very descriptive and naming a variable 11 is poor practice.

这篇关于动态填充的Andr​​oid微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆