====更新====自定義列表視圖與微調
代碼塊中有一個錯字,所以讓你們感到困惑。我想要做的是獲得列表視圖的列表項目的id,它擁有我現在單擊的微調框。
==== ====更新
我執行具有微調和文本框中爲每個列表項的自定義列表視圖。我想在列表視圖的列表項中使用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.
}
@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;
}
可以添加適配器的完整代碼嗎? –