我在列表视图中有一个微调器,因此当从哪个列表项中选择微调器值时如何获取列表项的值。
请回答此问题
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolderItem viewHolder;
if(convertView==null){
inflater = ((Activity) context).getLayoutInflater();
convertView = inflater.inflate(R.layout.cart_item, parent, false);
viewHolder = new ViewHolderItem();
viewHolder.toptext = (TextView) convertView.findViewById(R.id.cartname);
viewHolder.prc = (TextView) convertView.findViewById(R.id.textView76);
viewHolder.shp = (TextView) convertView.findViewById(R.id.textView77);
viewHolder.subtotal = (TextView) convertView.findViewById(R.id.textView79);
viewHolder.img = (ImageView) convertView.findViewById(R.id.imageView7);
viewHolder.spinner = (Spinner)convertView.findViewById(R.id.spinner);
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolderItem) convertView.getTag();
}
final CartResponse response = getItem(position);
int subtotal1=0;
mydb = new DBHelper(getContext());
if(response != null) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
R.array.qty, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
viewHolder.spinner.setAdapter(adapter);
viewHolder.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
response.getid();
if(mydb.updateCart(Integer.parseInt(response.getid()),pos)) {
Toast.makeText(getContext(),"updated", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
subtotal1=Integer.parseInt(response.getPrice()) + Integer.parseInt(response.getShipping());
viewHolder.toptext.setText(response.getPname());
viewHolder.prc.setText("Rs."+response.getPrice());
//Log.d("key",""+response.getPrice());
viewHolder.shp.setText("Rs."+response.getShipping());
viewHolder.subtotal.setText("Sub total Rs."+subtotal1);
Picasso.get().load("https://www.exmple.com/photos/"+response.getPhoto()+".png").placeholder(R.drawable.placeholder).memoryPolicy(MemoryPolicy.NO_CACHE).networkPolicy(NetworkPolicy.NO_CACHE).into(viewHolder.img);
}
所以我想要列表中项目的值,我可以从中选择微调框,也可以选择微调框值