I'm new to android studio and I have an issue where I can't get my custom listview menu to open when an ImageView is clicked. Here is my code that I have at the minute. I have tried to get a toggle to work but nothing I do helps!
我是android studio的新手,我遇到了一个问题,当点击ImageView时我无法打开自定义列表视图菜单。这是我现在的代码。我试图让切换工作,但我没有帮助!
MainActivity
final List<Nav> navList= new ArrayList<Nav>();
navList.add(new Nav("Profile"));
navList.add(new Nav("Feed"));
navList.add(new Nav("Maps"));
navList.add(new Nav("Most Popular"));
navList.add(new Nav("Settings"));
navList.add(new Nav("Report a Bug"));
ArrayAdapter<Nav> navadapter = new ArrayAdapter<Nav>(this,android.R.layout.simple_list_item_1, navList);
final ListView lv= (ListView) findViewById(left_drawer);
lv.setAdapter(navadapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int itemPosition = position;
switch(itemPosition) {
case 0:
Intent menuItem = new Intent(MainActivity.this, UserProfileActivity.class);
startActivity(menuItem);
break;
case 1:
menuItem = new Intent(MainActivity.this, MainActivity.class);
startActivity(menuItem);
break;
case 2:
menuItem = new Intent(MainActivity.this, UserMapActivity.class);
startActivity(menuItem);
break;
case 3:
menuItem = new Intent(MainActivity.this, UserMapActivity.class);
startActivity(menuItem);
break;
case 4:
menuItem = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(menuItem);
break;
case 5:
menuItem = new Intent(MainActivity.this, UserMapActivity.class);
startActivity(menuItem);
break;
}
}
});
navbut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
customListView1.toggle();
}
});
}
1 个解决方案
#1
0
I kept playing around with the code and the below worked:
我一直在玩代码和下面的工作:
navbut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.openDrawer(GravityCompat.START);
}
});
#1
0
I kept playing around with the code and the below worked:
我一直在玩代码和下面的工作:
navbut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.openDrawer(GravityCompat.START);
}
});