0
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 .

Aswin N
  • 11
  • 5
  • There are plenty of answers available in SO itself.Refer http://stackoverflow.com/questions/35061528/android-unable-to-increment-or-decrement-value-from-list-item/35061939#35061939 answer for more details. – Jas Mar 03 '16 at 06:03

1 Answers1

0

Try Using interface or Callback. Pass the number in the method in Adapter and Implement that method and Set the Textview in that method by passing the Position.

Study some thing about call back. You will find.

Avinash Verma
  • 2,572
  • 1
  • 18
  • 22
  • Check out this link. If Understand then Ok otherwise let me know. http://stackoverflow.com/questions/9343241/passing-data-between-a-fragment-and-its-container-activity – Avinash Verma Mar 03 '16 at 09:04