我正在尝试向我的应用程序添加导航视图,但由于某种原因,我无法让它响应它包含的任何项目上的任何点击事件.
我的activity_main.xml文件如下所示:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/navheader"
app:menu="@menu/menu_navigation" />
<LinearLayout
...
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
在我的MainActivity.java中,我有这个代码用于创建NavigationView及其项目选择监听器:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
...
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
// This method will trigger on item Click of navigation menu
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
if(menuItem.isChecked()) menuItem.setChecked(false);
else menuItem.setChecked(true);
mDrawerLayout.closeDrawers();
switch(menuItem.getItemId()) {
case R.id.nav_item_fragment:
// open a fragment
Toast.makeText(getApplicationContext(),"Items Selected",Toast.LENGTH_SHORT).show(); …Run Code Online (Sandbox Code Playgroud) 我有一台托管服务器的虚拟机,位于192.168.18.此服务器正在端口20000上侦听来自我的Android应用程序的连接.我在本地这样做是为了测试目的.
Genymotion虚拟机位于192.168.57.1,它似乎无法与其他服务器通信.
有没有办法改变Genymotion,以便它可以在192.168.1/24子网中运行,或者让它们正常通信?