问题描述
几乎每个链接我已经提到的每个堆栈问题,所以任何人都可以告诉我我的代码中有什么错误.以下是我的代码:
Almost every link every stack questions I referred already so please can anyone tell that what is my mistake in my code..Following is my code:
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
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 >
任何人都可以建议我..这是什么问题???我没有收到任何错误导航抽屉可以正确显示,但是当我在导航抽屉项上选择时,因此没有其他任何活动处于打开状态.
Can anyone please suggest me.. What is the problem??? I didn't get any error Navigation drawer is shown properly but when I select on navigation Drawer item so no any other activity is open..
推荐答案
只是一个建议,请开始使用 NavigationView .如果您正在此处搜索教程,则可以找到有关如何使用.
Just a suggestion please start using NavigationView recommended by android. In case you are searching for tutorials here you can find detailed example of how to use NavigationView in android.
这篇关于如何在导航抽屉项目上启动新活动,请单击其在我的代码中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!