2017-10-29 18 views
0

ナビゲーションレイアウトでシェアを実装することができますし、私はこのコードを使用し、共有アイテムの仕事をしたいが、それはは、どのように私は、ナビゲーションアプリを持っている

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

    if (id == R.id.nav_download) { 
     // Handle the camera action 
    } else if (id == R.id.nav_favorite) { 

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

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

     id.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent myIntent = new Intent(Intent.ACTION_SEND); 
       myIntent.setType("text/plain"); 
       String shareBody="Your Body Here"; 
       String shareSub="Your Subject Here"; 
       myIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub); 
       myIntent.putExtra(Intent.EXTRA_TEXT,shareBody); 
       startActivity(Intent.createChooser(myIntent,"Share using")); 

      } 
     }); 

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

    } 

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

を動作しません。項目。 私もShareViewを試しましたが、アンドロイドはこれをサポートしていないと思います。

+0

'onNavigationItemSelected(MenuItem item)'アイテムをクリックすると、 –

+0

'onNavigationItemSelected'の中で' clickListener'を削除する必要はありません。すべてのことを正しく行えばうまくいくでしょう。 – Ibrahim

+0

スイッチ/ケース構成について知りたいことがあります。 –

答えて

0
public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int id = item.getItemId(); 

    if (id == R.id.nav_download) { 
     // Handle the camera action 
    } else if (id == R.id.nav_favorite) { 

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

    } else if (id == R.id.nav_share) { 
     Intent myIntent = new Intent(Intent.ACTION_SEND); 
     myIntent.setType("text/plain"); 
     String shareBody="Your Body Here"; 
     String shareSub="Your Subject Here"; 
     myIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub); 
     myIntent.putExtra(Intent.EXTRA_TEXT,shareBody); 
     startActivity(Intent.createChooser(myIntent,"Share using")); 

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

    } 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawer.closeDrawer(GravityCompat.START); 
    return true; 
} 
関連する問題