I am having two buttons in the child view of expandable list view "minus" and "plus".I just need to increase the count of the variable (say int count=0). if I keep this variable on global of the adapter it will take the same count for all child of the group item. then I kept the variable inside the getChildView() as a local variable,Increment or decrements of the count can be done inside the on click listener of the two buttons minus and plus respectively and obviously changed the variable into final. And we know that final variable values cannot be changed.
I am too confused how to do this,is there any best way to do which I am not aware of here is my code. Expandable list view Adapter class:
get child view method:
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
ExChildModel model=(ExChildModel) getChild(groupPosition, childPosition);
if (convertView == null) {
convertView = inf.inflate(R.layout.pro_items, null);
}
RelativeLayout rl_main=(RelativeLayout)convertView.findViewById(R.id.rl_main);
RelativeLayout rl_color=(RelativeLayout)convertView.findViewById(R.id.rl_color);
LinearLayout ll_text=(LinearLayout)convertView.findViewById(R.id.ll_text);
LinearLayout ll_add=(LinearLayout)convertView.findViewById(R.id.ll_add);
TextView tv_subtitle=(TextView)convertView.findViewById(R.id.tv_subtitle);
TextView tv_sub=(TextView)convertView.findViewById(R.id.tv_sub);
final TextView tv_cost=(TextView)convertView.findViewById(R.id.tv_cost);
final TextView tv_number=(TextView)convertView.findViewById(R.id.tv_number);
ImageView iv_minus=(ImageView)convertView.findViewById(R.id.iv_minus);
ImageView iv_plus=(ImageView)convertView.findViewById(R.id.iv_plus);
tv_subtitle.setTypeface(gotham_book);
tv_sub.setTypeface(gotham_light);
tv_cost.setTypeface(gotham_book);
tv_number.setTypeface(gotham_book);
tv_subtitle.setText(model.getHeader());
tv_sub.setText(model.getDescription());
tv_cost.setText(Constants.currency+model.getPrice());
final int price=Integer.parseInt(model.getPrice());
iv_minus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (count!=0) {
count--;
tv_number.setText(String.valueOf(count));
FragmentMenu.tv_count.setText(String.valueOf(count));
int total=count*price;
FragmentMenu.tv_cart_money.setText(Constants.currency+String.valueOf(total));
}else {
FragmentMenu.tv_count.setVisibility(View.INVISIBLE);
FragmentMenu.tv_cart_money.setText(Constants.currency+"0");
}
}
});
iv_plus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (count>=0&&count!=99) {
count++;
tv_number.setText(String.valueOf(count));
FragmentMenu.tv_count.setVisibility(View.VISIBLE);
FragmentMenu.tv_count.setText(String.valueOf(count));
int total=count*price;
FragmentMenu.tv_cart_money.setText(Constants.currency+String.valueOf(total));
}
}
});
return convertView;
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire