1
工作好像displayView變量是不兼容的空隙,我嘗試一個元素的選擇,每次添加一個進度對話框成抽屜式導航開關不符合的AsyncTask
public class AsyncClass extends AsyncTask<Void, String, Void> {
\t private Context context;
\t ProgressDialog dialog = new ProgressDialog(context);
\t public AsyncClass(Context cxt) {
\t context = cxt;
\t }
\t @Override
\t protected void onPreExecute() {
\t dialog.setTitle("Please wait");
\t dialog.show();
\t }
\t @Override
\t protected Void doInBackground(Void... unused) {
\t \t
\t \t public void displayView(int position) { /*the message here is :void is an invalid type for the variable displayView*/
\t \t \t
\t \t \t
\t \t \t Fragment fragment = null;
\t \t \t switch (position) {
\t \t \t
\t \t \t case 1:
\t \t \t \t fragment = new HomeFragment();
\t \t \t \t break;
\t \t \t case 2:
\t \t \t \t fragment = new CalendarioFragment();
\t \t \t \t break;
\t \t \t case 5:
\t \t \t \t fragment = new ContactoFragment();
\t \t \t \t break;
\t \t \t case 6:
\t \t \t \t fragment = new OnclickFragment();
\t \t \t \t break;
\t \t \t default:
\t \t \t \t break;
\t \t \t }
\t \t \t if (fragment != null) {
\t \t \t \t try{
\t \t \t \t FragmentManager fragmentManager = getFragmentManager();
\t \t \t \t fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
\t \t \t \t // update selected item and tit|le, then close the drawer
\t \t \t \t mDrawerList.setItemChecked(position, true);
\t \t \t \t mDrawerList.setSelection(position);
\t \t \t \t setTitle(navMenuTitles[position]);
\t \t \t \t mDrawerLayout.closeDrawer(mDrawerList);
\t \t \t \t }
\t \t \t \t catch(Exception E)
\t \t \t \t {
\t \t \t \t \t Log.e("MainActivity", "Error in creating fragment");
\t \t \t \t }
\t \t \t }
\t \t \t else {
\t \t \t \t // error in creating fragment
\t \t \t \t Log.e("MainActivity", "Error in creating fragment");
\t \t \t }
\t \t }
\t \t SystemClock.sleep(2000);
\t return (null);
\t }
\t @Override
\t protected void onPostExecute(Void unused) {
\t dialog.dismiss();
\t }
\t }