I have one edittext field and one \"search\" button. When I click on search, I have to display a list view with data corresponding to the values entered in the edittext. I h
If you were used android:entries
in ListView in xml file, Its called setAdapter()
method before addHeaderView. So remove android:entries
attribute from ListView in xml layout file. It will be work.
On android 2.3, add header after setAdapter (even if you have added early, then removed) will throw an exception. To hide or show a header dynamically, use setVisibility(). How? You can see Hiding header views.
I had the same problem today. I have multiple ListViews.. With the information from the first, it builds the list of the next one and everyone has setAdapter in it. For me, the best solution was to put
setListAdapter(null);
on top of the function, where I inflate the Header. I hope this helps..
After so much efforts i got solution for my side i hope this will helps someone too
i already set adpater at the last (after view added) but dont know why i was suffring from same error so here i did something like this code
// Set View here
View view = getLayoutInflater().inflate(R.layout.navigation_header,null);
mDrawerList.addHeaderView(view);
// init your adapter
adapter1 = new YourListAdapter(getApplicationContext(),blabla);
// set adapter into handler
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
mDrawerList.setAdapter(adapter1);
}
}, 100);
I put my adapter in to handler sometime it happends that adapter set faster then view so this code enough for me to solve this exception. :)