ListView Item's position repeated - android

I am creating a dynamic listview using fragment in which item's position are repeating after 6th index(Note- items are not repeating).
I have to change quantity of item on button click, but when I try to click and change quantity at index 0 it also changes the 7th index quantity.
Please help me out
Thanx in advance.
public class MenuListAdapter extends ArrayAdapter<DataModel> {
private Activity activity;
public String[] ItemsList = new String[1000];
public String[] ItemsRelPrice;
ArrayList<String> foodItemTitle = new ArrayList<>();
private static String currentTitle;
private String selection;
private String ttl;
public MenuListAdapter(Activity activity, int resource, List<DataModel> dataModelList) {
super(activity, resource, dataModelList);
this.activity = activity;
}
#Nullable
#Override
public DataModel getItem(int position) {
return super.getItem(position);
}
#Override
public int getCount() {
return super.getCount();
}
#Override
public long getItemId(int position) {
return super.getItemId(position);
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.food_item_list, parent, false);
holder = new ViewHolder(convertView);
final ImageButton addBtn = convertView.findViewById(R.id.img_add);
final ImageButton removeBtn = convertView.findViewById(R.id.img_remove);
final TextView qty = convertView.findViewById(R.id.item_quantity);
final TextView priceTtl = convertView.findViewById(R.id.txt_cost);
final TextView foodItem = convertView.findViewById(R.id.item_name);
final TextView foodPrice = convertView.findViewById(R.id.per_item_cost);
addBtn.setTag(position);
addBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.v("btn tag", String.valueOf(addBtn.getTag()));
Log.v("qty tag", String.valueOf(qty.getTag()));
Log.v("Price tag", String.valueOf(priceTtl.getTag()));
int curntQty = Integer.parseInt(qty.getText().toString()) + 1;
int costPerItem = Integer.valueOf(foodPrice.getText().toString());
if (qty.getTag() == addBtn.getTag())
qty.setText(String.valueOf(curntQty));
if (priceTtl.getTag() == addBtn.getTag())
priceTtl.setText(String.valueOf(costPerItem * curntQty));
new MenuPage().addItem(costPerItem);
}
});
removeBtn.setTag(position);
removeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (qty.getText().toString() != "0") {
int qtyTtl = Integer.parseInt(qty.getText().toString()) - 1;
qty.setText(String.valueOf(qtyTtl));
int costPerItem = Integer.valueOf(foodPrice.getText().toString());
int curPrice = Integer.valueOf(priceTtl.getText().toString());
priceTtl.setText(String.valueOf(curPrice - costPerItem));
new MenuPage().removeItem(costPerItem);
} else {
Toast.makeText(getContext(), "Add Item First", Toast.LENGTH_SHORT).show();
}
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
DataModel dataModel = getItem(position);
holder.foodItem.setTag(position);
holder.foodItem.setText(dataModel.getItemTitleFinal());
holder.foodPrice.setTag(position);
holder.foodPrice.setText(dataModel.getItemPriceFinal());
holder.foodType.setTag(position);
holder.foodType.setImageResource(dataModel.getItemImgFinal());
holder.addBtn.setTag(position);
holder.removeBtn.setTag(position);
holder.qty.setTag(position);
holder.priceCurnt.setTag(position);
return convertView;
}
private static class ViewHolder {
private TextView foodItem;
private TextView foodPrice;
private ImageView foodType;
private ImageButton addBtn;
private ImageButton removeBtn;
private TextView qty;
private TextView priceCurnt;
public ViewHolder(View v) {
foodItem = v.findViewById(R.id.item_name);
foodPrice = v.findViewById(R.id.per_item_cost);
foodType = v.findViewById(R.id.fdTypeImg);
addBtn = v.findViewById(R.id.img_add);
removeBtn = v.findViewById(R.id.img_remove);
qty = v.findViewById(R.id.item_quantity);
priceCurnt = v.findViewById(R.id.txt_cost);
}
}
}

I modified your adapter class. You need to have dataModelList which will act as source to inflate the view holders. Now, you need to supply the list through the constructor and make small modifications at places where I might have missed. Let me know if modifications are needed.
public class MenuListAdapter extends ArrayAdapter<DataModel> {
private Activity activity;
public String[] ItemsList = new String[1000];
public String[] ItemsRelPrice;
ArrayList<String> foodItemTitle = new ArrayList<>();
private static String currentTitle;
private String selection;
private String ttl;
//List of DataModel objects to inflate into view holders
private List<DataModel> dataModelList;
public MenuListAdapter(Activity activity, int resource, List<DataModel> dataModelList) {
super(activity, resource, dataModelList);
this.activity = activity;
//set the list in constructor
this.dataModelList = dataModelList;
}
#Nullable
#Override
public DataModel getItem(int position) {
return dataModelList.get(position);
}
#Override
public int getCount() {
return dataModelList.size();
}
#Override
public long getItemId(int position) {
return dataModelList.get(position).getId();
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.food_item_list, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//findViewById codes removed because they are unnecessary
//Copy to final object so that it can be used inside inner classes
final ViewHolder finalHolder = holder;
DataModel dataModel = getItem(position);
finalHolder.foodItem.setTag(position);
finalHolder.foodItem.setText(dataModel.getItemTitleFinal());
finalHolder.foodPrice.setTag(position);
finalHolder.foodPrice.setText(dataModel.getItemPriceFinal());
finalHolder.foodType.setTag(position);
finalHolder.foodType.setImageResource(dataModel.getItemImgFinal());
finalHolder.addBtn.setTag(position);
finalHolder.removeBtn.setTag(position);
finalHolder.qty.setTag(position);
finalHolder.priceCurnt.setTag(position);
finalHolder.addBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.v("btn tag", String.valueOf(finalHolder.addBtn.getTag()));
Log.v("qty tag", String.valueOf(finalHolder.qty.getTag()));
Log.v("Price tag", String.valueOf(finalHolder.priceCurnt.getTag()));
int curntQty = Integer.parseInt(finalHolder.qty.getText().toString()) + 1;
int costPerItem = Integer.valueOf(finalHolder.foodPrice.getText().toString());
if (finalHolder.qty.getTag() == finalHolder.addBtn.getTag())
finalHolder.qty.setText(String.valueOf(curntQty));
if (finalHolder.priceCurnt.getTag() == finalHolder.addBtn.getTag())
finalHolder.priceCurnt.setText(String.valueOf(costPerItem * curntQty));
new MenuPage().addItem(costPerItem);
}
});
finalHolder.removeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (finalHolder.qty.getText().toString() != "0") {
int qtyTtl = Integer.parseInt(finalHolder.qty.getText().toString()) - 1;
finalHolder.qty.setText(String.valueOf(qtyTtl));
int costPerItem = Integer.valueOf(finalHolder.foodPrice.getText().toString());
int curPrice = Integer.valueOf(finalHolder.priceCurnt.getText().toString());
finalHolder.priceCurnt.setText(String.valueOf(curPrice - costPerItem));
new MenuPage().removeItem(costPerItem);
} else {
Toast.makeText(getContext(), "Add Item First", Toast.LENGTH_SHORT).show();
}
}
});
return convertView;
}
private static class ViewHolder {
private TextView foodItem;
private TextView foodPrice;
private ImageView foodType;
private ImageButton addBtn;
private ImageButton removeBtn;
private TextView qty;
private TextView priceCurnt;
public ViewHolder(View v) {
foodItem = v.findViewById(R.id.item_name);
foodPrice = v.findViewById(R.id.per_item_cost);
foodType = v.findViewById(R.id.fdTypeImg);
addBtn = v.findViewById(R.id.img_add);
removeBtn = v.findViewById(R.id.img_remove);
qty = v.findViewById(R.id.item_quantity);
priceCurnt = v.findViewById(R.id.txt_cost);
}
}
}

Change your code addBtn.setOnClickListener to and do the same with removeBtn button.setOnClickListener
addBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.v("btn tag", String.valueOf(addBtn.getTag()));
Log.v("qty tag", String.valueOf(qty.getTag()));
Log.v("Price tag", String.valueOf(priceTtl.getTag()));
int curntQty = Integer.parseInt(qty.getText().toString()) + 1;
// update your quantity to data model here
dataModel.updateQuantiy(curntQty);
int costPerItem = Integer.valueOf(foodPrice.getText().toString());
/*if (qty.getTag() == addBtn.getTag())
qty.setText(String.valueOf(curntQty));*/
if (priceTtl.getTag() == addBtn.getTag())
priceTtl.setText(String.valueOf(costPerItem * curntQty));
new MenuPage().addItem(costPerItem);
// Notify that the data set change at the position to re-binding layout.
notifyItemChanged(position);
}
});
And
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
// Your normal code
DataModel dataModel = getItem(position);
holder.foodItem.setTag(position);
holder.foodItem.setText(dataModel.getItemTitleFinal());
holder.foodPrice.setTag(position);
holder.foodPrice.setText(dataModel.getItemPriceFinal());
holder.foodType.setTag(position);
holder.foodType.setImageResource(dataModel.getItemImgFinal());
holder.addBtn.setTag(position);
holder.removeBtn.setTag(position);
holder.qty.setTag(position);
holder.priceCurnt.setTag(position);
// add your quantity to textview
holder.qty.setText(dataModel.getQuantity());
return convertView;
}

Change following code:
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.food_item_list, parent, false);
holder = new ViewHolder(convertView);
final ImageButton addBtn = convertView.findViewById(R.id.img_add);
final ImageButton removeBtn = convertView.findViewById(R.id.img_remove);
final TextView qty = convertView.findViewById(R.id.item_quantity);
final TextView priceTtl = convertView.findViewById(R.id.txt_cost);
final TextView foodItem = convertView.findViewById(R.id.item_name);
final TextView foodPrice = convertView.findViewById(R.id.per_item_cost);
addBtn.setTag(position);
addBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.v("btn tag", String.valueOf(addBtn.getTag()));
Log.v("qty tag", String.valueOf(qty.getTag()));
Log.v("Price tag", String.valueOf(priceTtl.getTag()));
int curntQty = Integer.parseInt(qty.getText().toString()) + 1;
int costPerItem = Integer.valueOf(foodPrice.getText().toString());
if (qty.getTag() == addBtn.getTag())
qty.setText(String.valueOf(curntQty));
if (priceTtl.getTag() == addBtn.getTag())
priceTtl.setText(String.valueOf(costPerItem * curntQty));
new MenuPage().addItem(costPerItem);
}
});
removeBtn.setTag(position);
removeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (qty.getText().toString() != "0") {
int qtyTtl = Integer.parseInt(qty.getText().toString()) - 1;
qty.setText(String.valueOf(qtyTtl));
int costPerItem = Integer.valueOf(foodPrice.getText().toString());
int curPrice = Integer.valueOf(priceTtl.getText().toString());
priceTtl.setText(String.valueOf(curPrice - costPerItem));
new MenuPage().removeItem(costPerItem);
} else {
Toast.makeText(getContext(), "Add Item First", Toast.LENGTH_SHORT).show();
}
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
DataModel dataModel = getItem(position);
holder.foodItem.setTag(position);
holder.foodItem.setText(dataModel.getItemTitleFinal());
holder.foodPrice.setTag(position);
holder.foodPrice.setText(dataModel.getItemPriceFinal());
holder.foodType.setTag(position);
holder.foodType.setImageResource(dataModel.getItemImgFinal());
holder.addBtn.setTag(position);
holder.removeBtn.setTag(position);
holder.qty.setTag(position);
holder.priceCurnt.setTag(position);
return convertView;
}
private static class ViewHolder {
private TextView foodItem;
private TextView foodPrice;
private ImageView foodType;
private ImageButton addBtn;
private ImageButton removeBtn;
private TextView qty;
private TextView priceCurnt;
public ViewHolder(View v) {
foodItem = v.findViewById(R.id.item_name);
foodPrice = v.findViewById(R.id.per_item_cost);
foodType = v.findViewById(R.id.fdTypeImg);
addBtn = v.findViewById(R.id.img_add);
removeBtn = v.findViewById(R.id.img_remove);
qty = v.findViewById(R.id.item_quantity);
priceCurnt = v.findViewById(R.id.txt_cost);
}
}
To:
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.item_stock, parent, false);
convertView = inflater.inflate(R.layout.food_item_list, parent, false);
holder = new ViewHolder(convertView);
final ImageButton addBtn = convertView.findViewById(R.id.img_add);
final ImageButton removeBtn = convertView.findViewById(R.id.img_remove);
final TextView qty = convertView.findViewById(R.id.item_quantity);
final TextView priceTtl = convertView.findViewById(R.id.txt_cost);
final TextView foodItem = convertView.findViewById(R.id.item_name);
final TextView foodPrice = convertView.findViewById(R.id.per_item_cost);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
DataModel dataModel = getItem(position);
holder.foodItem.setTag(position);
holder.foodItem.setText(dataModel.getItemTitleFinal());
holder.foodPrice.setTag(position);
holder.foodPrice.setText(dataModel.getItemPriceFinal());
holder.foodType.setTag(position);
holder.foodType.setImageResource(dataModel.getItemImgFinal());
holder.addBtn.setTag(position);
holder.removeBtn.setTag(position);
holder.qty.setTag(position);
holder.priceCurnt.setTag(position);
holder.addBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.v("btn tag", String.valueOf(addBtn.getTag()));
Log.v("qty tag", String.valueOf(qty.getTag()));
Log.v("Price tag", String.valueOf(priceTtl.getTag()));
int curntQty = Integer.parseInt(qty.getText().toString()) + 1;
int costPerItem = Integer.valueOf(foodPrice.getText().toString());
if (qty.getTag() == addBtn.getTag())
qty.setText(String.valueOf(curntQty));
if (priceTtl.getTag() == addBtn.getTag())
priceTtl.setText(String.valueOf(costPerItem * curntQty));
new MenuPage().addItem(costPerItem);
}
});
holder.removeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (qty.getText().toString() != "0") {
int qtyTtl = Integer.parseInt(qty.getText().toString()) - 1;
qty.setText(String.valueOf(qtyTtl));
int costPerItem = Integer.valueOf(foodPrice.getText().toString());
int curPrice = Integer.valueOf(priceTtl.getText().toString());
priceTtl.setText(String.valueOf(curPrice - costPerItem));
new MenuPage().removeItem(costPerItem);
} else {
Toast.makeText(getContext(), "Add Item First", Toast.LENGTH_SHORT).show();
}
}
});
return convertView;
}
private static class ViewHolder {
private TextView foodItem;
private TextView foodPrice;
private ImageView foodType;
private ImageButton addBtn;
private ImageButton removeBtn;
private TextView qty;
private TextView priceCurnt;
public ViewHolder(View v) {
foodItem = v.findViewById(R.id.item_name);
foodPrice = v.findViewById(R.id.per_item_cost);
foodType = v.findViewById(R.id.fdTypeImg);
addBtn = v.findViewById(R.id.img_add);
removeBtn = v.findViewById(R.id.img_remove);
qty = v.findViewById(R.id.item_quantity);
priceCurnt = v.findViewById(R.id.txt_cost);
}
}

Related

android:how to use viewflipper in listview to animate one row at a time

I have a listview with a custom adapter.Each row of the listview contains two textviews and a viewflipper.
When I click a button, I want to animate/flip each row with a random text.
For animation, I used view flipper,but the animation is not working one after the other , rather it works simultaneously for all the rows.
My button click code is as follows.
public void onButtonClick(View view) {
customAdapter.setFlipRow(!(customAdapter.isFlipRow()));
listView.invalidateViews();
}
The custom adapter:
public class CustomAdapter extends BaseAdapter {
Context context;
String countryList[];
boolean flag[]= null;
int flags[];
LayoutInflater inflter;
Random r = null;
private static String TAG = "CustomAdapter";
public ViewHolder getViewHolder() {
return viewHolder;
}
ViewHolder viewHolder;
public boolean isFlipRow() {
return flipRow;
}
public void setFlipRow(boolean flipRow) {
this.flipRow = flipRow;
}
private boolean flipRow = false;
public CustomAdapter(Context applicationContext, String[] countryList) {
this.context = context;
this.countryList = countryList;
flag = new boolean[countryList.length];
for(int f = 0;f<flag.length;f++)
{
flag[f] = false;
}
inflter = (LayoutInflater.from(applicationContext));
r = new Random(5);
}
private static class ViewHolder {
TextView country;
TextView country1;
ViewFlipper viewFlipper;
ListView lv;
}
#Override
public View getView(int pos, View view, ViewGroup viewGroup) {
View v = view;
if(view == null)
{
viewHolder = new ViewHolder();
view = inflter.inflate(R.layout.listadapter, null);
viewHolder.country = (TextView) view.findViewById(R.id.textView);
viewHolder.country1 = (TextView) view.findViewById(R.id.bottomtextView);
viewHolder.viewFlipper = (ViewFlipper) view.findViewById(R.id.flipper);
viewHolder.lv = (ListView)view.findViewById(R.id.listView);
view.setTag(viewHolder);
}else {
viewHolder = (ViewHolder) view.getTag();
}
viewHolder.country.setText(countryList[pos]);
int rInt = r.nextInt(5);
if(isFlipRow()){
viewHolder.country1.setText("Random No: "+rInt);
viewHolder.viewFlipper.setFlipInterval(1000);
if(pos <= countryList.length-1)
{
flag[pos] = true;
if(pos == 0 && flag[pos]){
viewHolder.viewFlipper.startFlipping();
}
if(pos != 0 && flag[pos-1] == true){
viewHolder.viewFlipper.startFlipping();
flag[pos-1] = false;
/*viewHolder.viewFlipper.stopFlipping();
I tried to have a boolean flag for each row,
setting it before startFlipping() and resetting it after
stopFlipping().But adding this stopFlipping() here
stops all rows except first row and all rows flip at the
same time.Moreover getView is called only during setAdapter()
and invalidateviews().*/
}
if(pos == countryList.length-1){
Arrays.fill(flag,false);
}
}
}
else{
viewHolder.viewFlipper.stopFlipping();
Arrays.fill(flag,false);
}
return view;
}
}
All I need is to animate each row one at a time.But now all the rows are animating at the same time.Any insights or inputs will be really helpful.
Try this:
public void onButtonClick(View view) {
customAdapter.flipRow(view);
}
and adapter:
public class CustomAdapter extends BaseAdapter {
Context context;
String countryList[];
int rnds[];
LayoutInflater inflater;
Random r;
private boolean flipRow = false;
private int flipRowNum = 0;
Button btn;
final private static String TAG = "CustomAdapter";
final private static int FLIP_DELAY = 1000;
final private static int FLIP_COUNT = 2;
public boolean isFlipRow() {
return flipRow;
}
public void flipRow(View view) {
btn = (Button)view;
btn.setEnabled(false);
flipRow = true;
notifyDataSetChanged();
}
public CustomAdapter(Context context, String[] countryList) {
this.context = context;
this.countryList = countryList;
inflater = (LayoutInflater.from(context));
r = new Random(5);
rnds = new int[countryList.length];
for(int f = 0;f<rnds.length; f++)
{
rnds[f] = r.nextInt(5);
}
}
private class ViewHolder {
TextView country;
TextView country1;
ViewFlipper viewFlipper;
ListView lv;
}
#Override
public int getCount() {
return countryList.length;
}
#Override
public String getItem(int i) {
return countryList[i];
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int pos, View view, ViewGroup viewGroup) {
final ViewHolder viewHolder;
if(view == null)
{
viewHolder = new ViewHolder();
view = inflater.inflate(R.layout.listadapter, null);
viewHolder.country = (TextView) view.findViewById(R.id.textView);
viewHolder.country1 = (TextView) view.findViewById(R.id.bottomtextView);
viewHolder.viewFlipper = (ViewFlipper) view.findViewById(R.id.flipper);
//viewHolder.lv = (ListView)view.findViewById(R.id.listView);
view.setTag(viewHolder);
}else {
viewHolder = (ViewHolder) view.getTag();
}
viewHolder.country.setText(countryList[pos]);
viewHolder.country1.setText("Random No: " + rnds[pos]);
viewHolder.viewFlipper.setFlipInterval(0);
if(isFlipRow() && (pos == flipRowNum)){
viewHolder.viewFlipper.startFlipping();
viewHolder.viewFlipper.setFlipInterval(FLIP_DELAY);
viewHolder.viewFlipper.postDelayed(new Runnable() { //Stop flipping
#Override
public void run() {
viewHolder.viewFlipper.stopFlipping();
flipRow = !flipRow;
flipRowNum++;
if(flipRowNum == countryList.length) flipRowNum = 0;
btn.setEnabled(true);
}
}, (2*FLIP_COUNT - 1)*FLIP_DELAY + 50);
}
return view;
}
}
Hope that helps!

ListView Not updating properly afte using notifyDataSetChanged()

In adapter class i am trying to update 2 TextView after click event ,
holder.increase.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int qty = Integer.parseInt(holder.itemQuantity.getText().toString());
qty += 1;
holder.itemQuantity.setText(String.valueOf(qty));
holder.totalItemPrice.setText(String.valueOf(getTotal(position))+" ৳");
updateCartItemQuantity(position,holder.itemQuantity);
}
});
if i don't use notifyDataSetChanged(), first TextView change but not the second, but after using notifyDataSetChanged() that also stops. I am using BaseAdapter here.
adapter:
public class CartAdapter extends BaseAdapter {
private CartDatabaseSource cartDatabaseSource;
private Context context;
private ArrayList<CartModel> cartmodels;
private ShowCartItemsActivity showCartItemsActivity;
public CartAdapter(Context context, ArrayList<CartModel> cartmodels) {
cartDatabaseSource = new CartDatabaseSource(context);
this.context = context;
this.cartmodels = cartmodels;
this.showCartItemsActivity = (ShowCartItemsActivity) context;
}
private static class ViewHolder {
TextView itemName;
TextView itemPrice;
TextView itemQuantity;
TextView totalItemPrice;
TextView increase;
TextView decrease;
ImageView foodImage;
ImageView delete;
ImageView update;
}
#Override
public int getCount() {
return cartmodels.size();
}
#Override
public Object getItem(int position) {
return cartmodels.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#NonNull
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.cart_single_row,parent,false);
holder=new ViewHolder();
holder.itemName = (TextView) convertView.findViewById(R.id.cartItemName);
holder.itemPrice = (TextView) convertView.findViewById(R.id.cartItemPriceValue);
holder.itemQuantity = (TextView) convertView.findViewById(R.id.cartItemQuantityValue);
holder.totalItemPrice = (TextView) convertView.findViewById(R.id.cartItemTotalPriceValue);
holder.increase = (TextView) convertView.findViewById(R.id.increaseQuantity);
holder.decrease = (TextView) convertView.findViewById(R.id.decreaseQuantity);
holder.foodImage = (ImageView) convertView.findViewById(R.id.cartFoodImage);
holder.delete = (ImageView) convertView.findViewById(R.id.itemDeleteBtn);
holder.update = (ImageView) convertView.findViewById(R.id.updateQuantity);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
Picasso.with(context).load(cartmodels.get(position).getFoodImage()).into(holder.foodImage);
holder.itemName.setText(cartmodels.get(position).getFoodName());
holder.itemPrice.setText(String.valueOf(cartmodels.get(position).getFoodPrice())+" ৳");
holder.itemQuantity.setText(String.valueOf(cartmodels.get(position).getFoodQty()));
holder.totalItemPrice.setText(String.valueOf(getTotal(position))+" ৳");
holder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int id = cartmodels.get(position).getCartID();
final boolean status = cartDatabaseSource.deleteItem(id);
if(status){
context.startActivity(new Intent(context, ShowCartItemsActivity.class));
Toast.makeText(context, "deleted", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "couldn't delete", Toast.LENGTH_SHORT).show();
}
}
});
holder.update.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int id = cartmodels.get(position).getCartID();
int qty = Integer.parseInt(holder.itemQuantity.getText().toString());
final boolean status = cartDatabaseSource.updateCartItem(id,qty);
if(status){
context.startActivity(new Intent(context, ShowCartItemsActivity.class));
Toast.makeText(context, "updated", Toast.LENGTH_SHORT).show();
holder.update.setVisibility(View.GONE);
}else{
Toast.makeText(context, "couldn't update", Toast.LENGTH_SHORT).show();
}
}
});
holder.increase.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int qty = Integer.parseInt(holder.itemQuantity.getText().toString());
qty += 1;
holder.totalItemPrice.setText(String.valueOf(getTotal(position))+" ৳");
holder.itemQuantity.setText(String.valueOf(qty));
updateCartItemQuantity(position,holder.itemQuantity);
}
});
holder.decrease.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int qty = Integer.parseInt(holder.itemQuantity.getText().toString());
if(qty > 1){
qty -= 1;
holder.itemQuantity.setText(String.valueOf(qty));
holder.totalItemPrice.setText(String.valueOf(getTotal(position))+" ৳");
updateCartItemQuantity(position,holder.itemQuantity);
}
}
});
return convertView;
}
private void updateCartItemQuantity(int position,TextView itemQuantity){
//notifyDataSetChanged();
int id = cartmodels.get(position).getCartID();
int qty = Integer.parseInt(itemQuantity.getText().toString());
final boolean status = cartDatabaseSource.updateCartItem(id,qty);
if(status){
if(context instanceof ShowCartItemsActivity){
//((ShowCartItemsActivity)context).setTotalPrice();
}
}else{
Toast.makeText(context, "couldn't update", Toast.LENGTH_SHORT).show();
}
}
private double getTotal(int position) {
int qty = cartmodels.get(position).getFoodQty();
double price = cartmodels.get(position).getFoodPrice();
return Math.round(price * qty);
}
}
Instead of notifyDataSetChanged() you should use notifyItemChanged(position) this way you don't need to rebind all your views.
But you shouldn't need to use this if you are setting OnClickListener inside your onBindViewHolder.
Remove all code from onClick method and put this code:
cartmodels.get(position).setFoodQty(cartmodels.get(position).getFoodQty()+1);
notifyDataSetChanged();

how to make an imageview visible on click of another imageview inside same row of a listview

i am trying to make a imageview visible when another imageview on same row is getting clicked.There are two main imageviews which are visible and two imageviews which are invisible initially i need to make respective imageview visible on click of visible imageview.
public class MatchListAdapter extends BaseAdapter {
public static final String TAG = ".MatchListAdapter";
MatchStatListAdapter matchStatListAdapter;
public List<RowItem> _data;
private ArrayList<RowItem> users;
RowItem data;
private ArrayList<RowItem> arraylist;
Context _c;
ViewHolder v;
public Typeface tf;
View view_main;
ImageLoader imageLoader;
ViewHolder holder;
public static Integer[] mThumbIds = {R.drawable.delhi,
R.drawable.gujrat, R.drawable.punjab, R.drawable.kolkata, R.drawable.mumbai, R.drawable.pune,
R.drawable.banglore, R.drawable.hydrabad};
public static Integer[] arrow_images = {R.drawable.arrow_bg};
int check;
private final boolean[] selectedstates;
public MatchListAdapter(List<RowItem> selectUsers, Context context) {
_c = context;
_data = selectUsers;
this.arraylist = new ArrayList<RowItem>();
this.arraylist.addAll(_data);
tf = Typeface.createFromAsset(context.getAssets(), UriUtility.FONTPATH_dark);
imageLoader = new ImageLoader(context);
selectedstates = new boolean[_data.size()];
}
#Override
public int getCount() {
return _data.size();
}
#Override
public Object getItem(int i) {
return _data.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
#Override
public View getView(final int i, final View convertView, ViewGroup viewGroup) {
view_main = convertView;
if (view_main == null) {
LayoutInflater li = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view_main = li.inflate(R.layout.group_list_detail, null);
holder = new ViewHolder();
holder.team_one = (ImageView) view_main.findViewById(R.id.Image_team1);
holder.team_two = (ImageView) view_main.findViewById(R.id.Image_team2);
holder.arrow_one = (ImageView) view_main.findViewById(R.id.arrow_two);
holder.arrow_two = (ImageView) view_main.findViewById(R.id.arrow_two);
holder.date = (TextView) view_main.findViewById(R.id.Tview1_date);
holder.place = (TextView) view_main.findViewById(R.id.Tview1_place);
holder.vs = (TextView) view_main.findViewById(R.id.Tview1_vs);
holder.stat_one = (TextView) view_main.findViewById(R.id.Tview1_stats);
holder.stat_two = (TextView) view_main.findViewById(R.id.Tview2_stats);
view_main.setTag(holder);
holder.team_one.setTag(i);
holder.team_two.setTag(i);
} else {
holder = (ViewHolder) view_main.getTag();
Log.e("Inside", "here--------------------------- In view2 data.getTeam_B()" + data.getTeam_B());
}
data = (RowItem) _data.get(i);
holder.team_one.setImageResource(mThumbIds[Integer.valueOf(data.getTeam_A()) - 1]);
holder.team_two.setImageResource(mThumbIds[Integer.valueOf(data.getTeam_B()) - 1]);
holder.team_one.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.arrow_one.setVisibility(View.VISIBLE);
}
});
holder.team_two.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int position = (Integer) v.getTag();
Log.e(TAG, "position of image " + position + "position i = " + i);
}
});
holder.date.setTypeface(tf);
holder.place.setTypeface(tf);
holder.vs.setTypeface(tf);
holder.stat_one.setTypeface(tf);
holder.stat_two.setTypeface(tf);
holder.date.setText(data.getMatch_date());
holder.place.setText(data.getVenue_name());
holder.stat_one.setText(data.getMatch_date());
return view_main;
}
static class ViewHolder {
ImageView team_one, arrow_one, arrow_two;
ImageView team_two;
TextView date, place, vs;
TextView stat_one, stat_two;
ImageLoader imageLoader;
}
After some efforts its working, thank you guys for your answers. I am posting my answer below :
public class MatchListAdapter extends BaseAdapter {
public static final String TAG = ".MatchListAdapter";
MatchStatListAdapter matchStatListAdapter;
public List<RowItem> _data;
private ArrayList<RowItem> users;
RowItem data;
private ArrayList<RowItem> arraylist;
Context _c;
ViewHolder v;
public Typeface tf;
ListView listView;
ImageLoader imageLoader;
int match_id;
public static Integer[] mThumbIds = {R.drawable.arrow_bg,R.drawable.delhi,
R.drawable.gujrat, R.drawable.punjab, R.drawable.kolkata, R.drawable.mumbai, R.drawable.pune,
R.drawable.banglore, R.drawable.hydrabad};
int check;
RowItem rowItem;
JSONArray ja;
public MatchListAdapter(List<RowItem> selectUsers, Context context) {
_c = context;
_data = selectUsers;
this.arraylist = new ArrayList<RowItem>();
this.arraylist.addAll(_data);
tf = Typeface.createFromAsset(context.getAssets(), UriUtility.FONTPATH_dark);
imageLoader = new ImageLoader(context);
}
#Override
public int getCount() {
return _data.size();
}
#Override
public Object getItem(int i) {
return _data.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
#Override
public View getView(final int i, View convertView, ViewGroup viewGroup) {
View view = convertView;
Log.e(TAG, "starting = = 1111111111 position "+ i );
//if (convertView == null) {
LayoutInflater li = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.group_list_detail, null);
team_one = (ImageView) view.findViewById(R.id.Image_team1);
team_two = (ImageView) view.findViewById(R.id.Image_team2);
r1 = (RelativeLayout) view.findViewById(R.id.relative_one);
r2 = (RelativeLayout) view.findViewById(R.id.relative_two);
date = (TextView) view.findViewById(R.id.Tview1_date);
place = (TextView) view.findViewById(R.id.Tview1_place);
vs = (TextView) view.findViewById(R.id.Tview1_vs);
stat_one = (TextView) view.findViewById(R.id.Tview1_stats);
stat_two = (TextView) view.findViewById(R.id.Tview2_stats);
arrow_one = (ImageView) view.findViewById(R.id.arrow_one);
arrow_two = (ImageView) view.findViewById(R.id.arrow_two);
//}
data = (RowItem) _data.get(i);
team_one.setImageResource(mThumbIds[Integer.valueOf(data.getTeam_A())]);
team_two.setImageResource(mThumbIds[Integer.valueOf(data.getTeam_B())]);
date.setText(data.getMatch_date());
place.setText(data.getVenue_name());
stat_one.setText(data.getComments());
boolean one = data.getCheckedBox();
boolean two = data.getCheckedBoxtwo();
if(one){
arrow_one.setVisibility(View.VISIBLE);
}
if (two){
arrow_two.setVisibility(View.VISIBLE);
}
r1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
data = (RowItem) _data.get(i);
ImageView arrow_one = (ImageView) v.findViewById(R.id.arrow_one);
if (data.getCheckedBox() == false) {
arrow_one.setVisibility(View.VISIBLE);
data.setCheckedBox(true);
} else {
arrow_one.setVisibility(View.INVISIBLE);
data.setCheckedBox(false);
}
}
});
r2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ImageView arrow_two = (ImageView) v.findViewById(R.id.arrow_two);
if (data.getCheckedBoxtwo() == false) {
arrow_two.setVisibility(View.VISIBLE);
data.setCheckedBoxtwo(true);
} else {
arrow_two.setVisibility(View.INVISIBLE);
data.setCheckedBoxtwo(false);
}
}
});
view.setTag(data);
return view;
}
}

Android Drawer – Change Icon onClick

I have got a simple navigation drawer with a header (see picture).
What I want to do now is whenever the header (listview-item with position 0) is clicked to either change the down-arrow-icon (bottom right corner of header) to an up-arrow-icon or to rotate it so the arrow points up. How can i achieve this with my adapter?
My List-Adapter:
public class MyAdapter extends BaseAdapter {
private String[] _navTitles;
private int[] _navIcons;
private String _nameHeader;
private int _profileHeader;
private String _emailHeader;
public int _arrowHeader;
public MyAdapter(String[] navTitles, int[] navIcons, String nameHeader, String emailHeader, int profileHeader, int arrowHeader) {
_navTitles = navTitles;
_navIcons = navIcons;
_nameHeader = nameHeader;
_emailHeader = emailHeader;
_profileHeader = profileHeader;
_arrowHeader = arrowHeader;
}
#Override
public int getCount() {
return _navTitles.length;
}
#Override
public Object getItem(int position) {
return _navTitles[position];
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder viewHolder = null;
if (view == null) {
if (position == 0) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.header, parent, false);
viewHolder = new ViewHolder();
viewHolder.profileView = (CircleImageView) view.findViewById(R.id.circleView);
viewHolder.nameView = (TextView) view.findViewById(R.id.name);
viewHolder.emailView = (TextView) view.findViewById(R.id.email);
viewHolder.arrowView = (ImageView) view.findViewById(R.id.arrow);
viewHolder.holderID = 0;
view.setTag(viewHolder);
} else {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_row, parent, false);
viewHolder = new ViewHolder();
viewHolder.textView = (TextView) view.findViewById(R.id.rowText);
viewHolder.imageView = (ImageView) view.findViewById(R.id.rowIcon);
viewHolder.holderID = 1;
view.setTag(viewHolder);
}
} else {
viewHolder = (ViewHolder) view.getTag();
}
if (_navTitles.length > position && position != 0) {
viewHolder.textView.setText(_navTitles[position]);
viewHolder.textView.setTag(_navTitles[position]);
viewHolder.imageView.setImageResource(_navIcons[position]);
viewHolder.imageView.setTag(_navIcons[position]);
}
if (position == 0) {
viewHolder.profileView.setImageResource(_profileHeader);
viewHolder.nameView.setText(_nameHeader);
viewHolder.emailView.setText(_emailHeader);
viewHolder.arrowView.setImageResource(_arrowHeader);
}
return view;
}
public static class ViewHolder {
int holderID;
TextView textView;
ImageView imageView;
CircleImageView profileView;
TextView nameView;
TextView emailView;
ImageView arrowView;
}
}
Thanks for any help!
I solved it by myself. If anybody needs it:
final ViewHolder finalViewHolder = viewHolder;
viewHolder.arrowView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (finalViewHolder.arrowView.getTag().equals("down")) {
finalViewHolder.arrowView.setImageResource(R.drawable.ic_arrow_drop_up_white_48dp);
finalViewHolder.arrowView.setTag("up");
} else if (finalViewHolder.arrowView.getTag().equals("up")) {
finalViewHolder.arrowView.setImageResource(R.drawable.ic_arrow_drop_down_white_48dp);
finalViewHolder.arrowView.setTag("down");
}
}
});

listview with radio group error

everybody i am creating a custom listview with dynamic radiobuttons adding to radiogroup upto that i am getting what i want but when i try to select one radio button in first row then automatically first button in 5th ,9th,13 row is getting selected and when i select any button in second row then same button in 6th,8th,12th row is getting selected what i am doing wrong here and my adapter class
public class InteractiveArrayAdapter extends ArrayAdapter<Model> {
String tag = "Events";
private final List<Model> list;
private final Activity context;
public InteractiveArrayAdapter(Activity context, List<Model> list) {
super(context, R.layout.rowbuttonlayout, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox,checkbox1;
protected RadioGroup mgroup;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(tag," 3");
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowbuttonlayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
//viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
//viewHolder.checkbox1 = (CheckBox) view.findViewById(R.id.checkbox1);
viewHolder.mgroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
final RadioButton[] mbutton=new RadioButton[5];
for(int l=0;l<5;l++){
mbutton[l]=new RadioButton(context);
mbutton[l].setText("test"+l);
viewHolder.mgroup.addView(mbutton[l]);
}
viewHolder.mgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup mRadioGroup, int checkedId) {
for(int i=0; i<mRadioGroup.getChildCount(); i++) {
RadioButton btn = (RadioButton) mRadioGroup.getChildAt(i);
//int t=table.indexOfChild(table_row);
//System.out.println(t);
int t=mRadioGroup.getId();
System.out.println(t);
if(btn.getId() == checkedId) {
String text = btn.getText().toString();
// do something with text
Log.d(text," event1");
return;
}
}
}
});
view.setTag(viewHolder);
Log.d(tag,"me");
} else {
view = convertView;
Log.d(tag,"meeee");
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
Log.d(tag," event7");
return view;
}
}
i am posting my working code so that it will be helpfull to others have a look at it
public class InteractiveArrayAdapter extends ArrayAdapter<Model> implements OnClickListener {
String tag = "Events";
private final List<Model> list;
private final Activity context;
int li,jh;
public InteractiveArrayAdapter(Activity context, List<Model> list) {
super(context, R.layout.rowbuttonlayout, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox,checkbox1;
protected RadioGroup mgroup;
protected RadioButton mbutton;
}
#Override
public View getView( final int position, View convertView, ViewGroup parent) {
//Log.d(tag," 3");
View view =null;
if (convertView == null) {
//System.out.println("ok");
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowbuttonlayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.mgroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
final RadioButton[] mbutton=new RadioButton[5];
for(int l=0;l<5;l++){
mbutton[l]=new RadioButton(context);
mbutton[l].setText("test"+l+position);
mbutton[l].setId(l+1);
mbutton[l].setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
RadioButton byt=(RadioButton) v;
byt.isChecked();
byt.getId();
Model element = (Model) viewHolder.mgroup.getTag();
element.setBte(byt.getId());
element.gte((String) viewHolder.text.getText());
System.out.println("givemeresult");
}
});
viewHolder.mgroup.addView(mbutton[l]);
}
view.setTag(viewHolder);
viewHolder.mgroup.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).mgroup.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
view.getTag()).mgroup.getTag();
holder.text.setText(list.get(position).getName());
if (list.get(position).getName()==list.get(position).done()){
holder.mgroup.check(list.get(position).isSelected());
}
else {
holder.mgroup.clearCheck();
}
return view;
}
That's because views are reused. You have to set holder.mgroup in the else of if(convertView == null)
Your code a bit changed by me:
public class InteractiveArrayAdapter extends ArrayAdapter<Model> {
String tag = "Events";
private final List<Model> list;
private final Activity context;
public InteractiveArrayAdapter(Activity context, List<Model> list) {
super(context, R.layout.rowbuttonlayout, list);
this.context = context.getApplicationContext();
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox,checkbox1;
protected RadioGroup mgroup;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(tag," 3");
View view = convertView;
ViewHolder viewHolder = null;
final RadioButton[] mbutton = null;
if (view == null) {
LayoutInflater inflator = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflator.inflate(R.layout.rowbuttonlayout, null);
viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
//viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
//viewHolder.checkbox1 = (CheckBox) view.findViewById(R.id.checkbox1);
viewHolder.mgroup = (RadioGroup) view.findViewById(R.id.radioGroup1);
// I'm not sure about this..
// Begin
mbutton=new RadioButton[5];
for(int l=0;l<5;l++){
mbutton[l]=new RadioButton(context);
mbutton[l].setText("test"+l);
viewHolder.mgroup.addView(mbutton[l]);
}
viewHolder.mgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup mRadioGroup, int checkedId) {
for(int i=0; i<mRadioGroup.getChildCount(); i++) {
RadioButton btn = (RadioButton) mRadioGroup.getChildAt(i);
//int t=table.indexOfChild(table_row);
//System.out.println(t);
int t=mRadioGroup.getId();
System.out.println(t);
if(btn.getId() == checkedId) {
String text = btn.getText().toString();
// do something with text
Log.d(text," event1");
return;
}
}
}
});
// End
view.setTag(viewHolder);
Log.d(tag,"me");
} else {
viewHolder = (ViewHolder) convertView.getTag();
// Begin
mbutton = viewHolder.mgroup;
// End
Log.d(tag,"meeee");
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
Log.d(tag," event7");
return view;
}
}
My implementation of an imageView (stripped):
public class DealAdapter extends ArrayAdapter<DealObject> {
private Context mContext;
private Activity mActivity;
private ArrayList<DealObject> mItems;
private int mXmlId;
public DealAdapter(Context context, int textViewResourceId, ArrayList<DealObject> items, Activity activity) {
super(context, textViewResourceId, items);
this.mContext = context.getApplicationContext();
this.mActivity = activity;
this.mItems = items;
this.mXmlId = textViewResourceId;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
//View v = null;
View v = convertView;
ViewHolder holder = null;
RemoteImageLoader imageLoader = new RemoteImageLoader(mContext, true);
RemoteImageView dealImage = null;
DealObject mo = mItems.get(position);
try {
if (v == null) {
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(mXmlId, null);
holder = new ViewHolder();
dealImage = (RemoteImageView) v.findViewById(R.id.deal_image);
holder.dealImage = dealImage;
v.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the ImageView.
holder = (ViewHolder) convertView.getTag();
holder.dealImage.setBackgroundColor(Color.WHITE);
dealImage = holder.dealImage;
}
if(mo.getImage() != null){
// calling reset is important to prevent old images from displaying in a recycled view.
dealImage.reset();
holder.dealImage.setImageUrl(imageUrl);
try {
holder.dealImage.loadImage();
}
catch (Exception ex) {
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return v;
}
private static final class ViewHolder {
private RemoteImageView dealImage;
}
}

Categories

Resources