내 문제는 onOptionsItemSelected가 호출되었지만 작동하지 않는 작업 표시 줄 항목을 클릭하는 것입니다.sherlockactionbar를 사용하여 탐색이 작동하지 않습니다.
뒤로 버튼 만 작동하면됩니다. 여기 내 코드는, 이것은 SherlockFragment 파일에 있습니다 :
actionbar = getSherlockActivity().getSupportActionBar();
actionbar.setDisplayHomeAsUpEnabled(true);
@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
inflater.inflate(R.menu.menu_detail, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.detailitem1:
break;
case android.R.id.home:
getActivity().onBackPressed();
break;
default:
return super.onOptionsItemSelected(item);
}
return false;
}
메뉴 항목이 com.actionbarsherlock.view.MenuItem입니다. setHasOptionsMenu (true)를 추가했습니다. onCreate에서 onCreateView도 시도했습니다. 에서는
@Override
public void onBackPressed() {
Saved = SP.getBoolean("saved", false);
if ((getSupportFragmentManager().findFragmentByTag("detail") == null)
| mTwoPane) {
ready = true;
} else
ready = false;
if (!Saved && ready) {
new AlertDialog.Builder(this)
.....
}else if (Saved && ready){
super.onBackPressed();
}else {
someListFragment Fragment = new someListFragment();
Fragment .setArguments(getIntent().getExtras());
Fragment .setHasOptionsMenu(true);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, Fragment, "listview")
.commit();
}
}
상기 준비 우리는 첫 번째 단편에있는 경우, 우리는 두 개의 창 모드이므로 태블릿을 사용하는 경우, 또는 경우에 해당하는 onbackpressed (:
onBackPressed는 그것 SherlockFragmentActivity, 본 인 그래서 두 번째는 null이다).
다시 버튼을 누르면 모든 것이 정상적으로 작동하고 조각이 교체됩니다. 하지만 작업 표시 줄에서 뒤로 버튼을 클릭하면 이전 활동으로 돌아갑니다.
내가 getActivity()를 chage하더라도 onBackPressed(); onBackPressed의 else 문은 작동하지 않습니다.
해결책을 아는 사람은 누구입니까? 내가 뭘 잘못 했습니까?
*하지만 작업 표시 줄에서 뒤로 버튼을 클릭하면 이전 활동으로 돌아갑니다. * - 기본 동작이어야합니다. 당신의 의견에는 어떻게해야합니까? – Luksprog
onbackpressed의 else 문이므로 조각을 대체하십시오 – executioner
Nevermind 해결책을 찾았습니다 :) – executioner