Android : Change navigation drawer list onstart

on Saturday, September 20, 2014


I would like to change the navigation drawer listview content when the app is launched. I'm tryng to do this with AsyncTask that is executed in onStart() method, but the navigation drawer list showed is always empty. This is my code:



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new UpdateTask().execute();
setContentView(R.layout.activity_main);

mTitle = mDrawerTitle = getTitle();
navMenuTitles = getResources().getStringArray(R.array.menu_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);


// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, partite));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());


In onPostExecute method i fill the adapter (List<String> partite = new ArrayList<String>();) in this way:



@Override
protected void onPostExecute(String result) {
partite.add(partita1.toUpperCase());
partite.add(partita2.toUpperCase());
partite.add(partita3.toUpperCase());
partite.add(partita4.toUpperCase());
partite.add(partita5.toUpperCase());
partite.add(partita6.toUpperCase());
partite.add(partita7.toUpperCase());
partite.add(partita8.toUpperCase());
partite.add(partita9.toUpperCase());
partite.add(partita10.toUpperCase());
progressD.dismiss();
}


Navigation drawer shows this items only if in onCreate() method i add manually a string like:



partite.add("hello");


then, navigation drawer will have this item and others added in asynctask. How can i solve this problem?


0 comments:

Post a Comment