Reputation: 49
I have Json data and bind listview.It's ok. When I click on the button in the row, the textbox on the wrong line is being updated.
My adapter codes.Thank you all in advance.
Hi guys,
I have Json data and bind listview.It's ok. When I click on the button in the row, the textbox on the wrong line is being updated.
My adapter codes.Thank you all in advance.
public class UrunAdapter extends ArrayAdapter<Urunler> {
ArrayList<Urunler> urunlist;
private static LayoutInflater vi;
int Resource;
ViewHolder holder;
private Context context;
public ArrayList<UrunlerSecilen> secilenUrunler=new ArrayList<UrunlerSecilen>();;
public UrunAdapter(Context context, int resource, ArrayList<Urunler> objects) {
super(context, resource, objects);
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource = resource;
urunlist = objects;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = vi.inflate(R.layout.row, parent, false);
ViewHolder holder = new ViewHolder();
//setting up the Views
convertView.setTag(holder);
}
ViewHolder holder = (ViewHolder) convertView.getTag();
holder.tvUrunAdi=(TextView)convertView.findViewById(R.id.tvUrunAdi);
holder.tvFiyat=(TextView)convertView.findViewById(R.id.tvFiyat);
holder.imgUrunFoto=(ImageView)convertView.findViewById(R.id.imgUrunFoto);
holder.btnArttir=(TextView)convertView.findViewById(R.id.btnArttir);
holder.btnEksilt=(TextView)convertView.findViewById(R.id.btnEksilt);
final EditText edtAdet=(EditText)convertView.findViewById(R.id.edtAdet);
holder.btnArttir.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String strAdetVal=edtAdet.getText().toString();
int adetValue=Integer.parseInt(strAdetVal);
if (adetValue>=20)
{
adetValue=20;
}
else
{
adetValue=adetValue+1;
}
edtAdet.setText(Integer.toString(adetValue));
}
});
holder.btnEksilt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String strAdetVal=edtAdet.getText().toString();
int adetValue=Integer.parseInt(strAdetVal);
if (adetValue<=0)
{
adetValue=0;
}
else
{
adetValue=adetValue-1;
}
edtAdet.setText(Integer.toString(adetValue));
}
});
holder.tvUrunAdi.setText(urunlist.get(position).getUrunAdi());
Picasso.with(context).load(urunlist.get(position).getFoto()).fit().into(holder.imgUrunFoto);
holder.tvFiyat.setText(urunlist.get(position).getFiyat());
return convertView;
}
static class ViewHolder {
public TextView tvUrunAdi;
public TextView tvFiyat;
public ImageView imgUrunFoto;
public EditText edtAdet;
public TextView btnArttir;
public TextView btnEksilt;
public TextView btnEkle;
public TextView lblAdet;
public TextView tvUrunId;
}
private static class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}
Upvotes: 0
Views: 257
Reputation: 8272
Try this following code:
Register your Edittext
in ViewHolder
class then
Change your code onclick of button as below
String strAdetVal=edtAdet.getText().toString();
Instance of use this
String strAdetVal=holder.edtAdet.getText().toString();
I hope this may help you
Upvotes: 2