I am having textview txtQuantity in my dashboard activity. I wrote separate class for custom adapter which will contain sold products.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
list = (ListView) findViewById(R.id.listSoldItems);
txtAmount = (TextView) findViewById(R.id.txtAmount);
txtItems = (TextView) findViewById(R.id.txtItems);
// init listview
adapter = new Sold_item_adaptor(Dashboard.this, soldItemsList);
list.setAdapter(adapter);
I can remove items from list using adapter. Code for removing items is written in adapter class.
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.list_row_sold_item, null);
TextView txtListItem = (TextView) vi.findViewById(R.id.txtListItem);
final TextView txtQuantity = (TextView) vi.findViewById(R.id.txtQuantity);
ImageView imgCancel = (ImageView) vi.findViewById(R.id.imgCancel);
HashMap<String, String> mapData = new HashMap<String, String>();
mapData = data.get(position);
txtListItem.setText(mapData.get("product"));
txtQuantity.setText(mapData.get("qty"));
imgCancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
doButtonOneClickActions(txtQuantity, position);
}
});
return vi;
}
private void doButtonOneClickActions(TextView txtQuantity, int rowNumber) {
// Do the actions for Button one in row rowNumber (starts at zero)
data.remove(rowNumber);
notifyDataSetChanged();
}
On my dashboard activity I am maintaining number of items selected, total amount. Now if I remove item from listview, code from custom adapter removes the item but how can I get notification / signal on dashboard activity to update quantity.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…