public class MyCustomAdapter extends ArrayAdapter public class MyCustomAdapter extends ArrayAdapter {
public ArrayList<String> list = new ArrayList<>();
// Context context;
// LayoutInflater inflater ;
Fragment fragmentContext;
public MyCustomAdapter(Context c, int textViewResourceId, ArrayList listItmes,
Fragment fragmentContext) {
super(c, textViewResourceId, listItmes);
this.list = listItmes;
this.fragmentContext = fragmentContext;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = fragmentContext.getLayoutInflater(null);
view = inflater.inflate(R.layout.list_item, parent, false);
}
if (list != null) {
//Handle TextView and display string from your list
TextView listItemText = (TextView) view.findViewById(R.id.list_item_string);
listItemText.setText(list.get(position));
final TextView dis = (TextView) view.findViewById(R.id.text_view_list_cart);
//Handle buttons and add onClickListeners
ImageButton deleteBtn = (ImageButton) view.findViewById(R.id.delete_btn);
ImageButton addBtn = (ImageButton) view.findViewById(R.id.add_btn);
deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do something
}
});
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do something
// Toast.makeText(getContext(), "item " +list.get(position) + " added", Toast.LENGTH_LONG).show();
}
});
}
return view;
}
}
Once i press the '+' button i want to increment textview to '1' and in another class called cart,the selected item should be added to cart and the similar reverse action should be taken when i press minus button .