私はカスタムリストビューを持っており、すべての行に対して1つの編集テキストと1つのボタンがあります。 私はそのボタンをクリックすると、編集テキストの価値を得たいだけです。カスタムリストビューに配置されたedittextから値を取得する方法
画像のように、私たちは、カートに追加]ボタンをクリックしたとき量のためにあるのEditTextの値を取得したいです。私は以下のようなものだったアダプターやコードを使用することについては :
public class ProductList_Adapter extends ArrayAdapter {
Context context;
int resource;
List<ProductList_ModelClass> productList_modelClasses = new ArrayList<>();
TextView tv_product_title;
TextView tv_product_price;
ImageView img_productImage;
RatingBar rb_custom_productlist;
EditText et_productQty;
Button btn_addto_Cart;
String product_Qty;
public ProductList_Adapter(Context context, int resource, List objects) {
super(context, resource, objects);
this.context = context;
this.resource = resource;
this.productList_modelClasses = objects;
}
@Override
public int getCount() {
return this.productList_modelClasses.size();
}
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater layoutInflater = ((Activity) context).getLayoutInflater();
convertView = layoutInflater.inflate(resource, parent, false);
}
img_productImage = (ImageView) convertView.findViewById(R.id.img_productImage);
tv_product_title = (TextView) convertView.findViewById(R.id.tv_product_title);
tv_product_price = (TextView) convertView.findViewById(R.id.tv_product_price);
rb_custom_productlist = (RatingBar) convertView.findViewById(R.id.rb_custom_productlist);
et_productQty = (EditText) convertView.findViewById(R.id.et_productQty);
btn_addto_Cart = (Button) convertView.findViewById(R.id.btn_addto_Cart);
Picasso.with(context)
.load(productList_modelClasses.get(position).getProduct_image())
.resize(250, 250)
.placeholder(R.mipmap.icon_placeholder) // optional
.error(R.mipmap.icon_error) // optional
.into(img_productImage);
tv_product_title.setText(productList_modelClasses.get(position).getProduct_name());
rb_custom_productlist.setRating(productList_modelClasses.get(position).getProduct_rating());
tv_product_price.setText("₹ " + productList_modelClasses.get(position).getProduct_price());
product_Qty = et_productQty.getText().toString();
btn_addto_Cart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, product_Qty + , Toast.LENGTH_SHORT).show();
}
});
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, productList_modelClasses.get(position).getProduct_name(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, ProductActivity.class);
intent.putExtra("product_id", productList_modelClasses.get(position).getProduct_id());
context.startActivity(intent);
}
});
return convertView;
}
}
の可能性のある重複した[アンドロイド - カスタムArrayAdapterとリストビューの各EditTexts値を取得します](http://stackoverflow.com/questions/23953066/android-get-each-edittexts-values-of-listview-with -custom-arrayadapter) – Rahul