2015-12-16 20 views
0

幾乎每一個我已經提到,所以請任何人都可以告訴大家,什麼是我在我的代碼錯誤.. 繼每個堆棧問題聯繫起來是我的代碼:如何開始導航抽屜項新的活動單擊它不是在我的代碼工作

public class Attdce extends Activity{ 

    DrawerLayout mDrawerLayout; 
    ListView mDrawerList; 
    ActionBarDrawerToggle drawerListener; 
    String mTitle=""; 
    private String[] information; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_attendance); 

     mTitle=(String)getTitle(); 
     mDrawerLayout=(DrawerLayout)findViewById(R.id.drawer_layout); 
     mDrawerList=(ListView)findViewById(R.id.drawer_list); 
     information=getResources().getStringArray(R.array.Information); 
     mDrawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, information)); 
     mDrawerList.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 
       //Updated Attdce.this instead of Attendace.this 
       Toast.makeText(Attdce.this, information [position]+ " was selected", Toast.LENGTH_LONG).show(); 
        selectItem(position); 
      } 

     }); 
     drawerListener=new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_menu_black_24dp,R.string.drawer_open, R.string.drawer_close) 
     { 
      @Override 
      public void onDrawerClosed(View drawerView) { 
      getActionBar().setTitle(mTitle); 
      invalidateOptionsMenu(); 
      } 

      @Override 
        public void onDrawerOpened(View drawerView) { 
        getActionBar().setTitle("Select"); 
        invalidateOptionsMenu(); 
      } 
     }; 
     mDrawerLayout.setDrawerListener(drawerListener); 
     getActionBar().setHomeButtonEnabled(true); 
     getActionBar().setDisplayHomeAsUpEnabled(true); 
} 
public void selectItem(int position) 
      { 

       setTitle(information[position]); 
       mDrawerList.setItemChecked(position, true); 
       Intent intent1; 
       switch(position){ 
       case 0: 
        intent1 = new Intent(Attdce.this, AboutUs.class); 
        startActivity(intent1); 
        break; 

       case 1: 
        intent1 = new Intent(Attdce.this, Features.class); 
        startActivity(intent1); 
        break; 

       case 2: 
        intent1 = new Intent(Attdce.this, Help.class); 
        startActivity(intent1); 
        break; 

       case 3: 
        intent1 = new Intent(Attdce.this, SMSCredits.class); 
        startActivity(intent1); 
        break; 

       case 4: 
        intent1 = new Intent(Attdce.this, ChangePassword.class); 
        startActivity(intent1); 
        break; 

       case 5: 
        intent1 = new Intent(Attdce.this, Help.class); 
        startActivity(intent1); 
        break; 

       } 
      } 

      public void setTitle(String title) 
      { 
       getActionBar().setTitle(title); 
      } 

@Override 
    public boolean onOptionsItemSelected(MenuItem item) 
    { 
     if(drawerListener.onOptionsItemSelected(item)){ 
       return true; 
      } 
     return super.onOptionsItemSelected(item); 
    } 

@Override 
     protected void onPostCreate(Bundle savedInstanceState) { 
      // TODO Auto-generated method stub 
      super.onPostCreate(savedInstanceState); 
      drawerListener.syncState(); 
     } 


} 

ACTIVITY_ATTENDANCE.XML

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

     > 

    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    </FrameLayout> 
    <ListView 
     android:id="@+id/drawer_list" 

     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     android:divider="#111" 
     android:dividerHeight="1dp" 
     android:background="#009688" 
     android:listSelector="@drawable/list_selector"/> 

    //other xml code 

</android.support.v4.widget.DrawerLayout > 

任何人都可以請建議我..有什麼問題???我沒有抽屜式導航正確顯示任何錯誤,但是當我選擇的抽屜式導航項,這樣沒有任何其他活動是開放的..

+1

你能看到Toast消息嗎? –

+1

你有沒有在清單中定義你的活動? –

+0

更新清單 –

回答

0

嘗試關閉抽屜,前startActivity(intent1)

case 5: 
        final intent1 = new Intent(Attdce.this, Help.class); 
           drawer.closeDrawers(); 
           drawer.postDelayed(new Runnable() { 
            @Override 
            public void run() { 
             startActivity(intent1); 
            } 
           }, 200); 
           break; 
+0

感謝您的迴應,但它不工作爲了我.. – Asmi

相關問題