因此,我通过执行File-> New - > Project - > Navigation Drawer Activity,使用Android Studio 2.1.2创建了一个Navigation Drawer Activity
。我有4个布局文件作为从MainActivity访问TextView
- nav_header_main.xml
- content_main.xml
- app_bar_main.xml
- activity_main.xml中
content.main.xml
拥有的helloTextView
ID的TextView
(我已经手动设置)。 在MainActivity
上,一个方法处理导航项目选择事件。现在我的目标是更改content.main.xml
文本视图的文本,并将文本设置为用户选择的内容。请注意下面的代码块的评论 -
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
// I want to change the content of helloTextView here
// I.E setText("You Selected Camera!")
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
我该如何去建立这个?
'((TextView)findViewById(R.id.helloTextview)).setText(“You Selected Camera!”)'? – sonictt1
究竟是什么问题?只要做到这一点常规的方式^ – Vucko
@sonictt1工作!我是新手。请将其作为答案发布。 非常感谢 – envyM6