0
我有Json數據並綁定listview.It沒關係。 當我點擊行中的按鈕時,錯誤行上的文本框正在更新。Android - Listview錯誤的位置Getview
我的適配器代碼。謝謝大家。
嗨,大家好,
我JSON數據並結合listview.It的確定。 當我點擊行中的按鈕時,錯誤行上的文本框正在更新。
我的適配器代碼。謝謝大家。
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);
}
}
}
沒有工作,我恨這個列表視圖 – Developer007
你faceing什麼問題發表您的logcat @ Gowthaman中號 –
我在列表視圖row.For例如我按下第一行點擊按鈕。第一行和最後一行按鈕背景變化。我點擊第二個按鈕。第二個按鈕和上一個按鈕顏色變化。 – Developer007