如何从android中的列表视图中获取选定的微调器值?

时间:2013-08-17 13:10:49

标签: java android android-listview

我有一个带有textview和spinner的listview,它对list中的每个微调器都有相同的值.textview和spinner的两个值分别在xml文件中。如何为微调器中的每一行选择微调器值...根据相对textview ...我完全初学到安卓...

1 个答案:

答案 0 :(得分:0)

WhateverAdapter中添加以下方法:

public void setOnSpinnerItemSelectedListener(OnItemSelectedListener listener){
    this.mSpinnerItemSelectedListener = listener;
}

getView()方法中:

public View getView(int position, View convertView, ViewGroup parent){
     //...

     viewHolder.spinner.setOnItemSelectedListener(mSpinnerItemClickListener);
     //.....
     return convertView;
}

然后在Activity或任何地方:

MyAdapter adapter = new MyAdapter(Context....);
adapter.setOnSpinnerItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        // your code here
    }

    @Override
    public void onNothingSelected(AdapterView<?> parentView) {
        // your code here
    }

});
myListView.setAdapter(adapter)