Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 选择android导航中的项目_Java_Android_Navigation_Selecteditem - Fatal编程技术网

Java 选择android导航中的项目

Java 选择android导航中的项目,java,android,navigation,selecteditem,Java,Android,Navigation,Selecteditem,我想在导航中选择一个项目,但我不能;为什么?有人能帮我吗 public class Add_Disease extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{ Databasehelp myDb; EditText editName; Button btnAddData; private DrawerLayout mDrawer ,dlDraw

我想在导航中选择一个项目,但我不能;为什么?有人能帮我吗

public class Add_Disease extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{

    Databasehelp myDb;
    EditText editName;
    Button btnAddData;
    private DrawerLayout mDrawer ,dlDrawer;
    private Toolbar toolbar;
    private NavigationView nvDrawer;
    ActionBarDrawerToggle drawerToggle;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add__disease);
        myDb =new Databasehelp(this);

        editName =(EditText)findViewById(R.id.editText_Add_disease);
        btnAddData=(Button)findViewById(R.id.button5_Disease);
        AddData();


        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);




        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout1);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view1);
        navigationView.setNavigationItemSelectedListener(this);
    }

    public void AddData(){
        btnAddData.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        boolean isInserted = myDb.insertData_Desaese(editName.getText().toString());
                        if (isInserted = true)
                            Toast.makeText(Add_Disease.this, "data inserted", Toast.LENGTH_LONG);
                        else
                            Toast.makeText(Add_Disease.this, "data not inserted", Toast.LENGTH_LONG);
                    }
                }

        );

    }
    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout1);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }
   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

   @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

      if (id == R.id.nav_camara) {
            // Handle the camera action
        }
        else if (id == R.id.nav_gallery) {

                Intent intent3 = new Intent(this,Show_Disease_Medicines.class);

                startActivity(intent3);
            }

         else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout1);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

您可以在导航侦听器中添加一些日志吗

Log.e("Debug","case one") ;
并与日志猫进行检查

在导航侦听器中,我建议使用如下切换情况:

Switch(view. GetId()) {
Case id1:
Break;
Case id2:
Break
} 
对于代码示例,很抱歉,我正在打电话