複数の配列があります。そして私はGridViewに送った。だから、これは一例です:ArrayListの値をBaseAdapterのGridViewから取得します。
アレイA:5,3,2,6
アレイB:車、ナイフ、ラップトップ、ファン
私は2つのボタンがあります。プラスとマイナスがあります。 +/- ボタンを押すと、自動的に配列Aの値が変化します。たとえば、car(5)の値を(2)に変更すると、Array Aの値は次のようになります。2,3,2,6
したがって、問題はArrayList状態で再度取得することです。
public class CustomGridView4 extends BaseAdapter {
private ArrayList<ListItem> listData;
private LayoutInflater layoutInflater;
private Context context;
private int count = 0;
private DBHelper myDb;
public CustomGridView4(Context context, ArrayList<ListItem> listData) {
this.listData = listData;
layoutInflater = LayoutInflater.from(context);
this.context = context;
myDb = new DBHelper(context);
}
@Override
public int getCount() {
return listData.size();
}
@Override
public Object getItem(int position) {
return listData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.afterlogin_product_gridview, null);
holder = new ViewHolder();
holder.headlineView = (TextView) convertView.findViewById(R.id.nama_produk);
holder.teaserView = (TextView) convertView.findViewById(R.id.harga);
holder.imageView = (ImageView) convertView.findViewById(R.id.img_produk);
holder.cmdMinus = (Button) convertView.findViewById(R.id.btn_min);
holder.cmdPlus = (Button) convertView.findViewById(R.id.btn_plus);
holder.qty = (TextView) convertView.findViewById(R.id.lbl_qty);
holder.layout1 = (LinearLayout) convertView.findViewById(R.id.layout1);
holder.satuan = (TextView) convertView.findViewById(R.id.satuan);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final ListItem newsItem = listData.get(position);
String satuan = "/ " + newsItem.getSatuan().toString();
String harga = newsItem.getReporterName().toString();
Integer qtys = newsItem.getQuantity();
holder.headlineView.setText(newsItem.getHeadline().toUpperCase());
holder.teaserView.setText(harga);
holder.satuan.setText(satuan);
holder.qty.setText(String.valueOf(qtys));
String a = newsItem.getUrl();
if (qtys == 0)
{
holder.layout1.setBackgroundResource(R.drawable.border_radius);
}
else
{
holder.layout1.setBackgroundResource(R.drawable.border_radius_gridview);
}
holder.cmdPlus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
count = newsItem.getQuantity();
count++;
newsItem.setQuantity(count);
System.out.println("ASD : " + newsItem.getQuantity());
holder.qty.setText("" + newsItem.getQuantity());
}
});
holder.cmdMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
count = newsItem.getQuantity();
if (count == 0) {
holder.qty.setText("0");
newsItem.setQuantity(0);
} else {
count--;
newsItem.setQuantity(count);
holder.qty.setText("" +newsItem.getQuantity());
}
}
});
if (holder.imageView != null) {
//new ImageDownloaderTask(holder.imageView).execute(newsItem.getUrl());
File file = new File(Environment.getExternalStoragePublicDirectory(".BlanjaPasar/Product"), a);
Picasso
.with(context)
.load(file)
.fit()
.noFade()
.into(holder.imageView);
}
holder.qty.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (!holder.qty.getText().toString().matches("0"))
{
holder.layout1.setBackgroundResource(R.drawable.border_radius_gridview);
}
else
{
holder.layout1.setBackgroundResource(R.drawable.border_radius);
}
}
});
return convertView;
}
static class ViewHolder {
TextView headlineView;
TextView teaserView;
ImageView imageView;
TextView satuan,qty;
Button cmdPlus,cmdMinus;
LinearLayout layout1;
}
}
アクションがholder.cmdMinus & holder.cmdPlusボタンである:ここに私のコードです。ここで
はスクリーンショットです:私は "Tambahkan" ボタンを押すと
だから、私は再びArrayListの値を取得したいです。それは可能ですか?
更新:
public ArrayList<ListItem> getListData() {
ArrayList<ListItem> listMockData = new ArrayList<ListItem>();
for (int i = 0; i < jArray; i++) {
ListItem newsData = new ListItem();
newsData.setKode(kode_prdct[i]);
newsData.setUrl(img_prdct[i]);
newsData.setHeadline(nama_prdct[i]);
newsData.setReporterName(harga_prdct[i]);
newsData.setSatuan(satuan_prdct[i]);
newsData.setQuantity(qty_prdct[i]);
listMockData.add(newsData);
}
return listMockData;
}
そして、これは私がGridViewのと呼ばれる方法です:ArrayListのは、私の活動から来てどこ
これはある
ArrayList<ListItem> listData = getListData();
product_gridview.setAdapter(new CustomGridView4(AfterLogin_HistoryDetail.this, listData));
を実装しますか?私はもう一度getListData()のようなメソッドを作る必要がありますか? –
@LeonardFebriantoあなたが取得したいポジションを知っているとします。 'listData.get(i).getQuantity()'が動作します。 'getListData()'をもう一度使うと、代わりに新しいリストが作成されます。これはアダプタのものではありません。 – Joshua
さて、私はそれを得る。ありがとう –