Advertisement
moonlightcheese

Untitled

Jan 9th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.93 KB | None | 0 0
  1. <!------ main.xml ------->
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:orientation="vertical"
  5.     android:layout_width="fill_parent"
  6.     android:layout_height="fill_parent"
  7.     >
  8.     <fragment android:name="com.conceptualsystems.smsmobile2.SmsTicketListFragment"
  9.               android:id="@+id/ticket_list_fragment"
  10.               android:layout_weight="1"
  11.               android:layout_height="wrap_content"
  12.               android:layout_width="wrap_content"/>
  13. </LinearLayout>
  14.  
  15.  
  16.  
  17. <!------ sms_ticket_list_layout ------>
  18. <?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  20.               android:layout_width="match_parent"
  21.               android:layout_height="match_parent">
  22.     <ListView android:id="@+id/ticket_list"
  23.               android:layout_width="match_parent"
  24.               android:layout_height="match_parent" />
  25. </LinearLayout>
  26.  
  27.  
  28. <!------ Main Activity.java ------>
  29. public class MainActivity extends FragmentActivity implements SmsTicketListFragment.OnTicketSelectedListener
  30. {
  31.     FragmentManager fm = getSupportFragmentManager();
  32.    
  33.     public void onTicketSelected(String selection) {
  34.         Fragment ticketReviewFragment = new SmsTicketReviewFragment();  //fm.findFragmentById(R.id.ticket_review_fragment);
  35.         FragmentTransaction transaction = fm.beginTransaction();
  36.  
  37.         //transaction.hide(fm.findFragmentById(R.id.ticket_list_fragment));
  38.         transaction.replace(R.id.ticket_list_fragment, ticketReviewFragment);
  39.         //transaction.detach(fm.findFragmentById(R.id.ticket_list_fragment));
  40.         //transaction.attach(ticketReviewFragment);
  41.         //transaction.detach(fm.findFragmentById(R.id.ticket_list_fragment));
  42.         transaction.addToBackStack(null);
  43.  
  44.         transaction.commit();
  45.        
  46.         //Log.i("SMSTICKET", selection);
  47.     }
  48.  
  49.     /** Called when the activity is first created. */
  50.     @Override
  51.     public void onCreate(Bundle savedInstanceState)
  52.     {
  53.         super.onCreate(savedInstanceState);
  54.         setContentView(R.layout.main);
  55.  
  56.        
  57.     }
  58. }
  59.  
  60.  
  61. <!------ Fragment A ------>
  62. public class SmsTicketListFragment extends Fragment {
  63.     OnTicketSelectedListener ticketSelectedListener;
  64.  
  65.     /*** View callback for Fragment class ***/
  66.     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  67.         View v = inflater.inflate(R.layout.sms_ticket_list_layout, container, false);
  68.         final List<String> listContent = new ArrayList<String>();
  69.         listContent.add("Selection One");
  70.         listContent.add("Selection Two");
  71.         listContent.add("Selection Three");
  72.         listContent.add("Selection Four");
  73.         listContent.add("Selection Five");
  74.         listContent.add("Selection Six");
  75.         listContent.add("Selection Seven");
  76.         listContent.add("Selection Eight");
  77.         listContent.add("Selection Nine");
  78.         listContent.add("Selection Ten");
  79.         ListAdapter listAdapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_list_item_1, listContent);
  80.         ListView listView = (ListView)v.findViewById(R.id.ticket_list);
  81.         listView.setAdapter(listAdapter);
  82.  
  83.         listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  84.             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  85.                 ticketSelectedListener.onTicketSelected(listContent.get(i));
  86.             }
  87.         });
  88.         return v;
  89.     }
  90.  
  91.     public void onCreate(Bundle savedInstanceState) {
  92.         super.onCreate(savedInstanceState);
  93.     }
  94.  
  95.     public void onAttach(Activity activity) {
  96.         super.onAttach(activity);
  97.         try {
  98.             ticketSelectedListener = (OnTicketSelectedListener) activity;
  99.         } catch(ClassCastException e) {
  100.             throw e;
  101.         }
  102.     }
  103.  
  104.     public interface OnTicketSelectedListener {
  105.         public void onTicketSelected(String selection);
  106.     }
  107. }
  108.  
  109.  
  110. <!------ Fragment B ------>
  111. public class SmsTicketReviewFragment extends Fragment {
  112.     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  113.         return inflater.inflate(R.layout.sms_ticket_review_layout, container, false);
  114.     }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement