我查了很多关于导航抽屉和按钮的问题,其中很多都是针对导航抽屉本身的按钮。我的问题是,我无法从具有导航抽屉的主活动中获取按钮移动到下一个活动。它会创建按钮但是点击器不会移动到以下活动,也不会举杯祝词让我知道点击器正在工作。
我使用了eclipse在您创建新导航抽屉时提供的模板。
public class UserMain extends Activity implements NavigationDrawerFragment.NavigationDrawerCallbacks {
Button one;
private NavigationDrawerFragment mNavigationDrawerFragment;
private CharSequence mTitle;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_main);
one = (Button) findViewById(R.id.button1);
System.out.println("Button1");
one.setOnClickListener(new View.OnClickListener() {
//There is a problem here!!!
@Override
public void onClick(View v) {
System.out.println(v.toString());
System.out.println("Button 1 pressed!");
// TODO Auto-generated method stub
Context context = getApplicationContext();
CharSequence text = "ONE";
int duration = Toast.LENGTH_SHORT;
Toast passwordToast = Toast.makeText(context, text, duration);
passwordToast.show();
}
});
mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager()
.findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
}