我试图从SimpleAdapter获取数据,但我不知道它的语法。示例代码:
month_selector.xml
<LinearLayout android:orientation="vertical">
<TextView
android:id="@+id/text"
android:text="Month of birth"
/>
<Spinner
android:id="@+id/spin_birthmonth"
android:entries="@array/birthmonth"
/>
</LinearLayout>活动页面
public class SomeActivity extends Activity {
SimpleAdapter adapter;
ListView lv;
protected List<HashMap<String, String>> fillMaps;
protected String[] from;
protected int[] to;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lv = (ListView) findViewById(R.id.room_list_view);
fillMaps = new ArrayList<HashMap<String, String>>();
from = new String[] {"title", "spinner"};
to = new int[] {R.id.text, R.id.spin_birthmonth};
HashMap<String, String> map = new HashMap<String, String>();
map.put("title", "Your month of birth");
fillMaps.add(map);
adapter = new rSimpleAdapter(this, fillMaps, R.layout.month_selector, from, to);
lv.setAdapter(adapter);
}
}我删掉了一些东西,让它看起来很清晰,如果我遗漏了什么,请告诉我。我想要做的是……
Spinner month = adapter.getSpinner(R.id.spin_month);但是我不知道从适配器内部获取微调器的语法是什么。如果可以解决问题的话,我可以让它成为一个自定义适配器。
发布于 2012-09-06 13:55:08
因为这是一个ListView,所以每个ListItem上都有一个微调器。因此,在获得行视图后,您将不得不获得微调器。我认为下面的代码应该可以工作。但我还没试过
int first = lv.getFirstVisiblePosition();
View item = lv.getChildAt(first + rowid); //rowid is the row on which the spinner you want.
Spinner month = (Spinner)item.findViewbyId(R.id.spin_month); 编辑:从post上看,这似乎是可行的
int firstPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount(); //
int wantedChild = rowid - firstPosition;
if (wantedChild < 0 || wantedChild >= listView.getChildCount()) {
return;
}
View item = lv.getChildAt(wantedChild);
Spinner month = (Spinner)item.findViewbyId(R.id.spin_month); https://stackoverflow.com/questions/12293340
复制相似问题