微调器在滚动listview时自动重置值。但如果我的项目很少,他们可以在屏幕上没有滚动我的应用程序完美地工作。单击按钮时,我检查listview的数字选择器的值。任何帮助都将不胜感激。提前谢谢。
我的适配器:
public class ProductListAdapterforListView extends BaseAdapter {
private Context mContext;
private List<piatto> mProductList;
Vibrator vibe;
MediaPlayer mp ;
//Constructor
public ProductListAdapterforListView(Context mContext, List<piatto> mProductList) {
this.mContext = mContext;
this.mProductList = mProductList;
}
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public int getCount() {
return mProductList.size();
}
@Override
public Object getItem(int position) {
return mProductList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = View.inflate(mContext, R.layout.row_data_list, null);
TextView n = (TextView)v.findViewById(R.id.namepiatto);
TextView p = (TextView)v.findViewById(R.id.prezzopiatto);
ImageView i = (ImageView) v.findViewById(R.id.imagepiatto);
com.shawnlin.numberpicker.NumberPicker numberPicker =v.findViewById(R.id.number_picker);
n.setText(mProductList.get(position).getNome());
p.setText(mProductList.get(position).getPrezzo()+" €");
Picasso.get().load(mProductList.get(position).getImmagine()).into(i);
numberPicker.setOnScrollListener(new NumberPicker.OnScrollListener() {
@Override
public void onScrollStateChange(NumberPicker view1, int scrollState) {
Vibrator vi = (Vibrator) view1.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vi.vibrate(12);
mp = MediaPlayer.create(view1.getContext(),R.raw.sound);
mp.start();
}
});
return v;
}
}
2条答案
按热度按时间ha5z0ras1#
在setonscrolllistener上创建一个对象似乎不是一个好主意,它在上下滚动期间被多次调用。如果你能提供更多的细节,那就太好了。
3okqufwl2#
我试图通过以下方式获取单击按钮后每个项目的数字选择器值: