我正在實現自定義列表視圖與自定義列表項目,其中有微調框和文本框。我想在列表視圖的列表項中使用onItemSelected()
保存選定的微調值,但我沒有任何想法找到包含用戶正在處理的微調控件的列表項。我怎麼能得到這個,任何人都可以幫助這個?自定義列表視圖與自定義列表項目有微調
以下是我在列表視圖適配器中的代碼。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = inflater.inflate(R.layout.listitem, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.view1 = (Spinner) listItemView.findViewById(R.id.view1);
viewHolder.view2 = (TextView) listItemView.findViewById(R.id.view2);
viewHolder.view1.setFocusable(false);
viewHolder.view2.setFocusable(false);
viewHolder.view1.setAdapter(view1Adapter);
viewHolder.view1.setPrompt("Select");
viewHolder.view1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedId = spinnerItemList.get(position).id;
// todo : need to find a way to get list item of list view, which has this spinner, like the position of getView().
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
listItemView.setTag(viewHolder);
}
CustomListItem item = listViewItemList.get(position);
ViewHolder viewHolder = listItemView.getTag();
viewHolder.view1.setSelection(item.view1Value);
viewHolder.view2.setText(String.valueOf(item.view2Value));
return listItemView;
}
@Loc是的,它不需要是實例,CustomListItem的索引會很好。 – user3110409