현재 탭과 OptionsMenu가있는 ActionBar가 있습니다. 내 탭은 각 프래그먼트를 제대로 열지 만 onOptionsItemSelected를 사용하여 프래그먼트를 여는 방법을 알 수 없습니다.Android onOptionsItemSelected 새 단편을 엽니 다.
@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();
if (id == R.id.action_info) {
new ParentInfoSectionFragement();
return true;
} else if (id == R.id.action_history){
new NotificationHistorySectionFragment();
return true;
}
return super.onOptionsItemSelected(item);
}
내가 시도한 것이 분명 잘못되었습니다.
모든 도움을 주시면 감사하겠습니다.
activity_main.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.parentprojectmobile.MainActivity" />
fragment_history.xml
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.parentprojectmobile.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/history_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_history" />
/RelativeLayout>
모든 조각이 원래 조각의 단지 복사본입니다 만 목적을 학습 textviews을 주셔서 감사합니다.
답장을 보내 주셔서 감사합니다. 불행히도 메뉴 항목을 선택하면 불행히도 앱이 중지되었습니다. message – Photekk
@Photekk이 게시물에 오류를 게시합니다. –
내 전화가 튕겨 나오는 팝업은 내가받은 – Photekk