选择导航抽屉项目时,无法显示片段

时间:2016-02-02 11:39:00

标签: android runnable android-navigation-drawer

MainActivity

使用 Runnable()平滑打开和关闭导航抽屉,但在选择抽屉项目时无法显示片段。

$string="<header>";
$imagesrc="";

While($row=$stmt->fetch()){
  $string+=$row['Title'];
  $imagesrc=$row['Image'];
}

$string+="</header>";
$stringImage="<img src='".$imagesrc."' />";

1 个答案:

答案 0 :(得分:0)

仅在runOnUiThread执行您的操作,而不是在Runnable中调用runOnUiThread。您的代码应如下所示:

public void onNavigationDrawerItemSelected(final int position,View view) {

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    FragmentManager fragmentManager = getSupportFragmentManager();
                    switch (position) {

                        case 0:
                            fragmentManager.beginTransaction().replace(R.id.container, new HomeFragment()).commit();
                            break;

                        case 1:
                            fragmentManager.beginTransaction().replace(R.id.container, new HomeFragment()).commit();
                            break;
                        case 2:
                             fragmentManager.beginTransaction().replace(R.id.container, new   HomeFragment()).commit();
  //                        Intent i = new Intent(con, SplashScreenActivity.class);
   //                        startActivity(i);
    //                        finish();
                            break;
                    }
                }
            });


    if (mDrawerLayout != null) {
        mDrawerLayout.closeDrawer(view);
        supportInvalidateOptionsMenu();
    }