I have a ListView filled with twitter tweets. I made a custom Tweet class so I could store a special type number. So, I have the Tweet class and custom ArrayAdapter:
class Tweet {
private int typeNumber; // My unique type number which does not come from Twitter
private String message;
// ... other tweet data
}
class TweetsAdapter extends ArrayAdapter<Tweet> {
private ArrayList<Tweet> tweets;
TweetsAdapter(Context context, int textViewResourceId, ArrayList<Tweet> tweets) {
super(context, textViewResourceId, tweets);
this.tweets = tweets;
}
public View getView(int position, View convertView, ViewGroup parent) {
// Inflate my own view and set my own tweet row information
}
}
There is a nav bar which has 4 Buttons representing the 4 special type numbers. I want to display a filtered tweet ListView when a person clicks on one of the type number buttons without destroying the data in the ArrayAdapter.
One approach I came up with is to break up my main tweets ArrayList into sub-ArrayLists and set a new ArrayAdapter with the corresponding sub-ArrayList on the ListView every time you click one of the Buttons. That seems inefficient to instantiate a new ArrayAdapter every time.
Is there a better way to display a filtered ListView while maintaining all the tweet data on the ArrayAdapter(I also tried looking at the filter class and it seems to destroy the data on the adapter to "filter")?