how to get component from listView?
yesterday I posted this question and got answer, and was able to do what 开发者_运维知识库I wanted.
multiple spinner but one in xml
but now the question is how to get each spinner from listView's row and do stuff with it?
in my code i have only injected String as a name to listAdapter?
ListView listView = (ListView) viewTxting.findViewById(R.id.ListViewTreeView);
for (int i = 0; i < names.size(); i++) {
listAdapter.add(names.get(i));
}
listView.setAdapter(listAdapter);
thanks in advance.
It depends on what you want to do with it. One option is to override [getView][1] on your adapter. This gives you access to each view as it is created.
Keep in mind that the ListView
reuses view objects as you scroll up and down, so you can't assume any default state for the provided view object. If you want to change some value for half of the views, you need to make sure to set it to the default for the other half.
listView.setAdapter(new ListAdapter(...) {
public View getView (int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
// do stuff with v here.
}
}
[1]: http://developer.android.com/reference/android/widget/Adapter.html#getView(int, android.view.View, android.view.ViewGroup)
精彩评论