0
안녕하세요, 나는 onOptionsItemSelected를 통해 메뉴 공유 버튼을 선택할 때 호출 할 수있는 공유 인 텐트를 만들려고합니다. 공유 버튼을 누르면 onOptionsItemSelected가 호출되지만 공유 옵션은 제공되지 않습니다. 여기서 오류가 무엇인지 말할 수 있습니까? 구현할 여러 가지 방법이 있지만이 기능이 작동하지 않는 이유를 얻고 싶습니다. 당신이 붙여 조각에서메뉴를 통해 의도 공유
public boolean onCreateOptionsMenu(Menu menu) {
/* Use AppCompatActivity's method getMenuInflater to get a handle on the menu inflater */
MenuInflater inflater = getMenuInflater();
/* Use the inflater's inflate method to inflate our menu layout to this menu */
inflater.inflate(R.menu.detail, menu);
/* Return true so that the menu is displayed in the Toolbar */
//MenuItem menuItem = menu.findItem(R.id.action_share);
//menuItem.setIntent(createShareForecastIntent());
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
String message = "Yes I am here";
// TODO (2) Launch the map when the map menu item is clicked
if(id == R.id.action_share) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
item.setIntent(createShareForecastIntent());
return true;
}
return super.onOptionsItemSelected(item);
}
private Intent createShareForecastIntent() {
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setText(mForecast + FORECAST_SHARE_HASHTAG)
.getIntent();
return shareIntent;
}
}
내가 item.setIntent 후 onOptionsItemSelected 방법에 추가 할 필요가 오버랩 복사하는 것을 잊지 (createShareForecastIntent을()) : 여기
코드는? 그 뜻을 창조 한 후에 나는 그것을 부르겠습니까? – sinay