2013-08-04 107 views
0

喜有福爾摩斯片段活動的運行也包含滑動菜單,我想這個活動之前,有閃屏,我不知道如何使按鈕在這個片段活動工作不能啓動濺活動之前Sherlockfragment活動

package com.androidbegin.sidemenututorial; 

    import com.actionbarsherlock.app.SherlockFragmentActivity; 
    import com.actionbarsherlock.view.Menu; 
    import com.actionbarsherlock.view.MenuItem; 

    import android.support.v4.app.FragmentTransaction; 
    import android.support.v4.app.Fragment; 
    import android.content.Intent; 
    import android.content.res.Configuration; 
    import android.os.Bundle; 
    import android.support.v4.app.ActionBarDrawerToggle; 
    import android.support.v4.widget.DrawerLayout; 
    import android.view.View; 
    import android.widget.AdapterView; 
    import android.widget.Button; 
    import android.widget.ListView; 
    import android.support.v4.view.GravityCompat; 

    public class MainActivity extends SherlockFragmentActivity { 

// Declare Variable 
DrawerLayout mDrawerLayout; 
ListView mDrawerList; 
ActionBarDrawerToggle mDrawerToggle; 
MenuListAdapter mMenuAdapter; 
String[] title; 
String[] subtitle; 
int[] icon; 
Fragment fragment1 = new Fragment1(); 
Fragment fragment2 = new Fragment2(); 
Fragment fragment3 = new Fragment3(); 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.drawer_main); 









    // Generate title 
    title = new String[] { "Main Menu", "Setting", 
      "About" }; 

    // Generate subtitle 
    subtitle = new String[] { "", "", 
      "" }; 

    // Generate icon 
    icon = new int[] { R.drawable.action_about, R.drawable.action_settings, 
      R.drawable.collections_cloud }; 

    // Locate DrawerLayout in drawer_main.xml 
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 

    // Locate ListView in drawer_main.xml 
    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); 

    // Pass results to MenuListAdapter Class 
    mMenuAdapter = new MenuListAdapter(this, title, subtitle, icon); 

    // Set the MenuListAdapter to the ListView 
    mDrawerList.setAdapter(mMenuAdapter); 

    // Capture button clicks on side menu 
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); 

    // Enable ActionBar app icon to behave as action to toggle nav drawer 
    getSupportActionBar().setHomeButtonEnabled(true); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

    // ActionBarDrawerToggle ties together the the proper interactions 
    // between the sliding drawer and the action bar app icon 
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
      R.drawable.ic_drawer, R.string.drawer_open, 
      R.string.drawer_close) { 

     public void onDrawerClosed(View view) { 
      // TODO Auto-generated method stub 
      super.onDrawerClosed(view); 
     } 

     public void onDrawerOpened(View drawerView) { 
      // TODO Auto-generated method stub 
      super.onDrawerOpened(drawerView); 
     } 
    }; 

    mDrawerLayout.setDrawerListener(mDrawerToggle); 

    if (savedInstanceState == null) { 
     selectItem(0); 
    } 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getSupportMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 

    if (item.getItemId() == android.R.id.home) { 

     if (mDrawerLayout.isDrawerOpen(mDrawerList)) { 
      mDrawerLayout.closeDrawer(mDrawerList); 
     } else { 
      mDrawerLayout.openDrawer(mDrawerList); 
     } 
    } 

    return super.onOptionsItemSelected(item); 
} 

// The click listener for ListView in the navigation drawer 
private class DrawerItemClickListener implements 
     ListView.OnItemClickListener { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, 
      long id) { 
     selectItem(position); 
    } 
} 

private void selectItem(int position) { 

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 
    // Locate Position 
    switch (position) { 
    case 0: 
     ft.replace(R.id.content_frame, fragment1); 
     break; 
    case 1: 
     ft.replace(R.id.content_frame, fragment2); 
     break; 
    case 2: 
     ft.replace(R.id.content_frame, fragment3); 
     break; 

    } 
    ft.commit(); 
    mDrawerList.setItemChecked(position, true); 
    // Close drawer 
    mDrawerLayout.closeDrawer(mDrawerList); 
} 

@Override 
protected void onPostCreate(Bundle savedInstanceState) { 
    super.onPostCreate(savedInstanceState); 
    // Sync the toggle state after onRestoreInstanceState has occurred. 
    mDrawerToggle.syncState(); 
} 

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    // Pass any configuration change to the drawer toggles 
    mDrawerToggle.onConfigurationChanged(newConfig); 
} 
    } 
+1

你應該讓你的splashscreen在一個單獨的Activity中完成,當它啓動時http://blog.blundell-apps.com/tut-splashscreen-with-progress-bar/ – Blundell

+0

是的,我在Splash.java我跑了一個線程5秒,並通過意向開始了這個活動,但是這給了一個例外,但在其他活動中,我做同樣的事情,並沒有例外 – user2624812

回答

0

並且您已將活動添加到清單?

+0

是的,我有........正如我早些時候告訴它的與不使用片段的其他活動和應用一起工作,但此sherlock片段活動不會運行,從而產生異常 – user2624812