there to textView sub and add. on click of add value will be add and if sub then value will be cut. adapter class.
public class ListAdapter extends ArrayAdapter {
ArrayList<RowModel> model;
Context mContext;
ArrayList<Integer> selections;
static class ViewHolder
{
TextView text,edittext;
ImageView indicator;
ImageView image;
TextView sub,add;
}
public ListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
mContext = context;
model = new ArrayList<RowModel>();
selections = new ArrayList<Integer>();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row == null)
{
LayoutInflater inflater =(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.list_row, null);
final ViewHolder holder = new ViewHolder();
holder.text = (TextView) row.findViewById(R.id.row_txt);
holder.image = (ImageView)row.findViewById(R.id.row_img);
holder.edittext = (TextView) row.findViewById(R.id.edittext);
holder.sub = (TextView) row.findViewById(R.id.listsub);
holder.add = (TextView) row.findViewById(R.id.listadd);
//holder.edittext.setText("0");
holder.indicator = (ImageView)row.findViewById(R.id.row_indicator);
ColorDrawable cd = new ColorDrawable(Color.parseColor("#FF007d7b"));
holder.indicator.setImageDrawable(cd);
row.setTag(holder);
}
final ViewHolder vh = (ViewHolder)row.getTag();
vh.image.setImageResource(model.get(position).resID);
vh.text.setText(model.get(position).country);
vh.edittext.setText(model.get(position).editText1);
vh.sub.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//notifyDataSetChanged();
// setNotifyOnChange(true);
int i = Integer.parseInt(vh.edittext.getText().toString());
i--;
vh.edittext.setText(""+i);
notifyDataSetChanged();
}
});
vh.add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//notifyDataSetChanged();
int i = Integer.parseInt(vh.edittext.getText().toString());
i++;
vh.edittext.setText(""+i);
}
});
return row;
}
public String getvalue(int i)
{
String ii = null;
if(!this.model.get(i).editText1.equals("0"))
{
ii = this.model.get(i).country + " "+this.model.get(i).editText1;
}
return ii;
}
}
now code for button,need to all value of qty on button click from main activity
public class MainActivity extends Activity {
private ListView list;
private ListAdapter listAdapter;
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list =(ListView) this.findViewById(R.id.list);
button1 = (Button)findViewById(R.id.button1);
listAdapter = new ListAdapter(this, 0);
this.initAdapter();
list.setAdapter(listAdapter);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
for(int i = 0; i <listAdapter.getCount();i++)
{
//listAdapter.updateSelection(i);
Toast.makeText(MainActivity.this, listAdapter.getvalue(i), 1).show();
//listAdapter.notifyDataSetChanged();
((ListAdapter)listAdapter).notifyDataSetChanged();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private void initAdapter()
{
RowModel row = new RowModel(R.drawable.china, "China","0");
listAdapter.addRow(row);
RowModel row2 = new RowModel(R.drawable.japan, "Japan","1");
listAdapter.addRow(row2);
RowModel row3 = new RowModel(R.drawable.korea, "Korea","2");
listAdapter.addRow(row3);
RowModel row4 = new RowModel(R.drawable.america, "America","3");
listAdapter.addRow(row4);
RowModel row5 = new RowModel(R.drawable.canada, "Canada","4");
listAdapter.addRow(row5);
RowModel row6 = new RowModel(R.drawable.england, "England","5");
listAdapter.addRow(row6);
RowModel row7 = new RowModel(R.drawable.france, "France","06");
listAdapter.addRow(row7);
}
}
my get/set class
public class RowModel {
int resID;
String country;
String editText1;
public RowModel(int rid, String country,String editText1)
{
this.resID = rid;
this.country = country;
this.editText1 = editText1;
}
public String getEditText1() {
return editText1;
}
public void setEditText1(String editText1) {
this.editText1 = editText1;
}
}