Java tutorial
/********************************************************************** * Copyright (c) 2015 Luka Kunic, "ItemDetailFragment.java" * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for * the specific language governing permissions and limitations under the License. * * Author: lkunic * Last modified: 08/02/2015 **********************************************************************/ package com.lkunic.lib.activityaddonlib.twopane.fragments; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.View; /** * A fragment representing a single item detail screen. */ public abstract class ItemDetailFragment extends Fragment { // The fragment argument representing the item ID that this fragment displays. public static final String ARG_ITEM_ID = "item_id"; /** * Id of the item that was selected in the list. */ private long mItemId; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null && savedInstanceState.containsKey(ARG_ITEM_ID)) { mItemId = savedInstanceState.getLong(ARG_ITEM_ID); } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putLong(ARG_ITEM_ID, mItemId); } /** * Set the id of the item that will be displayed in this fragment. */ public void setItemId(long id) { mItemId = id; } /** * Refresh the fragment content. Assumes a new item id was set. */ public void refreshContent() { View view = getView(); if (view != null) { setupContent(view); } } /** * The item Id that was passed in by the list activity. * @return */ protected long getItemId() { return mItemId; } /**************************************************************************************************/ /**** Abstract methods ****/ /**************************************************************************************************/ /** * Use to get the item data from the database. */ protected abstract void getItemData(); /** * Setup the fragment content. */ protected abstract void setupContent(View view); }