2015-04-21 15 views
2

我有这样的代码,请点击:我延长myClass的约抽屉类,我看到布局myClass的,但我不能在按钮

DrawerLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    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" /> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ListView 
      android:id="@+id/drawerList" 
      android:layout_width="180dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:background="#FFFFFF" 
      android:choiceMode="singleChoice" 
      android:divider="@android:color/darker_gray" 
      android:dividerHeight="1dp" 
      android:entries="@array/Functions" /> 
    </android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 

DrawerActivity:

public class Drawer extends Activity { 
    private DrawerLayout drawerLayout; 
    private ListView drawerList; 
    private ActionBarDrawerToggle mDrawerToggle; 
    private Intent intent; 
    public RelativeLayout fullLayout; 
    public FrameLayout frameLayout; 

    @Override 
    public void setContentView(int layoutResID) { 

     fullLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.activity_main, null); 
     frameLayout = (FrameLayout) fullLayout.findViewById(R.id.content_frame); 
     drawerLayout = (DrawerLayout) fullLayout.findViewById(R.id.drawerLayout); 
     drawerList = (ListView) fullLayout.findViewById(R.id.drawerList); 


     getLayoutInflater().inflate(layoutResID, frameLayout, true); 

     super.setContentView(fullLayout); 

     drawerList.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.Functions))); 
     drawerList.setOnItemClickListener(new DrawerItemClickListener()); 

     mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.app_name, R.string.app_name) { 
      public void onDrawerClosed(View view) {} 
      public void onDrawerOpened(View drawerView){} 
     }; 
     drawerLayout.setDrawerListener(mDrawerToggle); 

     getActionBar().setIcon(R.drawable.ic_drawer); 
     getActionBar().setDisplayHomeAsUpEnabled(true); 
     getActionBar().setHomeButtonEnabled(true); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.menu.menu, menu); 
     return super.onCreateOptionsMenu(menu); 
    } 

    public boolean onOptionsItemSelected(MenuItem item) { 
     if (mDrawerToggle.onOptionsItemSelected(item)) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

    private void selectItem(int position) { 
     drawerLayout.closeDrawers(); 
     switch (position) { 
      case 0: 
       intent = new Intent(this, 0Act.class); 
       startActivity(intent); 
       break; 
      case 1: 
       // intent = new Intent(this, 1Act.class); 
       break; 
      case 2: 
       intent = new Intent(this, 2Act.class); 
       startActivity(intent); 
       break; 
      case 3: 
       intent = new Intent(this, 3Act.class); 
       startActivity(intent); 
       break; 
      case 4: 
       // intent = new Intent(this, 4Act.class); 
       break; 
     } 
    } 

    private class DrawerItemClickListener implements ListView.OnItemClickListener { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      selectItem(position); 
     } 
    } 
} 

FirstActivity:

  public class 0Act extends Drawer implements ActionBar.TabListener { 
      ActionBar.Tab t1,t2,t3; 
      ActionBar actionBar; 
    Button oneButton; 
     final CharSequence[] items = {"1", "2", "3", "4"}; 
     AlertDialog.Builder ad; 

    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.0Act); 
    actionBar = getActionBar(); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 


       t1 = actionBar.newTab().setText("1"); 
       t2 = actionBar.newTab().setText("2"); 
       t3 = actionBar.newTab().setText("3"); 

       t1.setTabListener(this); 
       t2.setTabListener(this); 
       t3.setTabListener(this); 

       actionBar.addTab(t1); 
       actionBar.addTab(t2); 
       actionBar.addTab(t3); 
       actionBar.setSelectedNavigationItem(0); 

    oneButton= (Button) this.findViewById(R.id.oneButton); 
      oneButton.setOnClickListener(new View.OnClickListener(){@Override public void onClick(View v) {ad.show();}}); 

      ad = new AlertDialog.Builder(getActivity()); 
      ad.setTitle("Menu"); 
      ad.setItems(items, new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int item) {}}); 

      } 
    } 

我看到抽屉 - 我可以点击抽屉,但无法点击第一个活动的任何按钮。出了什么问题? 在将抽屉添加到许多活动之前,所有工作都很好,但现在我没有看到任何错误和活动不工作。

+1

您是否为您设置了一些clickListener按钮? – Vyncent

+0

问题是不正确的,Item1Activity扩展BaseActivity,并且您还没有添加BaseActvitiy类,您已经添加了BaseDrawerActivity,并且您期望从问题中获得解决方案?也添加布局代码 –

回答

0

提及super.onClick(v);在您的Item1Activity类中使用onClick方法

相关问题