我有一个动态创建视图的for循环。
for (int i=0;i<5;i++){
a=new ImageView();
tv=new TextView();
img=new ImageView();
spn=new Spinner();
img.setOnClickListener(this);//this is working for every view
spn.post(new Runnable){
@Override
public void run() {
Log.d("post","inside post");// here only last view is working
}
} //for loop ends
但是如何动态创建spinner.post或使其工作。 请帮忙。坚持了最后三天。谢谢。
答案 0 :(得分:0)
让你的活动实现OnItemSelectedListener,它是为微调器中选择的每个项目注册的callbak,然后在这个回调中实现你在每个视图上所需的内容。
您的班级定义:
public class SpinnerActivity extends Activity implements OnItemSelectedListener
在您的活动中实现onItemSelected回调:
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
如果您需要文档,请查看此http://developer.android.com/guide/topics/ui/controls/spinner.html;)