Advertisement
Guest User

ContentFragment

a guest
Jan 10th, 2013
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package com.example.test;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.support.v4.app.Fragment;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.TextView;
  10.  
  11. public class content_fragment extends Fragment {
  12.  
  13.     public static final int[] TextQuellen = new int[] { R.string.item1,
  14.             R.string.item2, R.string.item3 };
  15.     private int textIndex = -1;
  16.  
  17.     public void onAttach(Activity activity) {
  18.         super.onAttach(activity);
  19.         Bundle extras = getActivity().getIntent().getExtras();
  20.         if (extras != null) {
  21.             textIndex = extras.getInt("selectedIndex");
  22.         }
  23.  
  24.     }
  25.  
  26.     @Override
  27.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  28.             Bundle savedInstanceState) {
  29.         View view = inflater.inflate(R.layout.content_fragment, container,
  30.                 false);
  31.  
  32.         if (textIndex >= 0) {
  33.             TextView text = (TextView) view.findViewById(R.id.text_content);
  34.             text.setText(TextQuellen[textIndex]);
  35.         }
  36.         return view;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement