I have been searching for ages and trying for months. I can NEVER get my views (ANY view) to invalidate. What’s the problem here, can anyone please tell me? And can anyone tell me how to use these invalidate methods. Thanks in advance!
if(result.equals("true"))
{
View row = invoices.getChildAt(info.position);
//TextView bgr = (TextView) row.findViewById(R.id.status);
//bgr.setBackgroundResource(R.color.blue);
//row.setVisibility(View.GONE);
Animation anim = AnimationUtils.loadAnimation(Invoices.this, R.anim.down_to_top);
anim.setDuration(500);
invoices.getChildAt(info.position).startAnimation(anim );
final int row_pos = info.position;
new Handler().postDelayed(new Runnable() {
public void run() {
/*row.getInstance().remove(
FavouritesManager.getInstance().getTripManagerAtIndex(info.position)
);*/
ListView invoices = (ListView) findViewById(R.id.allInvoices);
View row = invoices.getChildAt(row_pos);
row.setVisibility(View.GONE);
getAllInvoices();
myAdapter.notifyDataSetChanged();
}
}, anim.getDuration());
Toast.makeText(getApplicationContext(), "Deleted!", Toast.LENGTH_SHORT).show();
}
update:
This is what I got now. It removes the view and animates correctly, but it still doesn’t invalidate?
ListView invoices = (ListView) findViewById(R.id.allInvoices);
View row = invoices.getChildAt(row_pos);
HashMap<String, String> lRow = invoice_items.get(row_pos);
lRow.remove(row);
row.setVisibility(View.GONE);
myAdapter.notifyDataSetChanged();
The reason why the call
notifyDataSetChangedis not working, is because the data set is not changed.Inside your
Handler, you alter the layout of theListViewitself. TheListViewis not more than a representation of anAdapter, which holds data.To understand how it works, this post will explain it.
Applying that on your code would output something like this: (PSUEDO)
inside Adapter: