Reputation: 4003
I want to know when my listview has no adapter set on it. I mean, is there a way to know when I have called setListAdapter(mAdapter); without a condition on my code?
I want to add a header to my listview, but just the first time as:
if(getListView().getAdapter() != null){
WWDisplayUtils.addHeaderButton(mTaxis, mAirport, AirportDetailsTaxi.this);
setListAdapter(mTaxiA);
}
else
mTaxiA.notifyDataSetChanged();
But is not doing what I want.
Upvotes: 3
Views: 5703
Reputation: 10938
Shouldn't
if(getListView().getAdapter() != null)
be
if(getListView().getAdapter() == null)
If you've already set a header or footer view, getAdapter() will return a WrapperListAdapter instead of the one you set with setListAdapter()
Upvotes: 8
Reputation: 30825
Can't you just call getAdapter() and see if its null or at least see if it's not equal to what you thought it should be? So like this:
if(mListView.getAdapter() != mAdapter){
//do one thing
}
else{
//do another thing
}
Upvotes: 1