I have a tablelayout that retrieves data from a *.txt file. For every line of data in the txt file, there will be one row of data.
Let's say I have two rows of data in the txt file right now, it makes sense that two tablerows will be generated.
Then, I added a OnLongPressListener which, when called, will delete one row of data from the txt file.
Now's the first question: After deleting data in the txt file, how do I refresh my tablelayout to reflect that change?
Second question is: After I get my first question solved, is it possible to have some kind of animation where one row will fade out or slide out instead of just disappearing outright?
Thanks!
Not sure if you are still looking for answer. But I came across this post facing kinda the same problem. Plus the fact that I was forced to use TableLayout
(the amount of code written using TableLayout
is huge and it wasn't my call to switch to ListView
).
What I ended up doing was to remove all the views from TableLayout
using:
`tableLayout.removeAllViews();`
But that's not gonna work if the number of rows after removal changes drastically. I needed to invalidate my view too, using a handler. Here is the rest of my code.
protected static final int REFRESH = 0;
private Handler _hRedraw;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tree_view_activity);
_hRedraw=new Handler(){
@Override
public void handleMessage(Message msg)
{
switch (msg.what) {
case REFRESH:
redrawEverything();
break;
}
}
};
...
}
private void redrawEverything()
{
tableLayout.invalidate();
tableLayout.refreshDrawableState();
}
There is only one part left and that's the part where you send a message to your handler to refresh your view. Here is the code for it:
_hRedraw.sendEmptyMessage(REFRESH);