android UISplitview controller version

Send Snippet To: Save this snippet to Code Collector Pro -- view all balzan's snippets
language: Objective-C
license: Other

Code for Snippet:

                
//activity layout file
 
 
<LinearLayout 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:layout_marginLeft="4dp"
    android:layout_marginRight="6dp"
    android:baselineAligned="false"
    android:divider="?android:attr/dividerHorizontal"
    android:orientation="horizontal"
    android:showDividers="middle"
    tools:context=".RundownListActivity"
    android:id="@+id/LinearLayout" >
 
 
 
    <fragment
        android:id="@+id/rundown_list"
        android:name="com.example.rundownplus_android.RundownListFragment"
        android:layout_width="0dp"		
         android:layout_weight="1"
        android:layout_height="match_parent"
        android:transcriptMode="normal" 
        tools:layout="@android:layout/list_content" />
 
 
       <FrameLayout
        android:id="@+id/story_detail_container"
         android:name="com.example.rundownplus_android.StoryDetailFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3" > 
        </FrameLayout> 
 
 
</LinearLayout>
 
 
 
 
//in activtiy
 
 
 
 
 
	// on preprerea menu
 
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
 
		Display display = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		int rotation = display.getRotation();
 
		if (rotation == 1 || rotation ==3){
			// hide the search button if is portrait and menu not being shown
			 RundownListFragment f = (RundownListFragment) getSupportFragmentManager() .findFragmentById(R.id.rundown_list);
			LinearLayout.LayoutParams params2 = (LayoutParams) f.getView().getLayoutParams();	// for the following test
 
			if(params2.weight != 1.0f){
				MenuItem item2 =(MenuItem) menu.findItem(R.id.action_search);
				item2.setVisible(false);
 
			}
		}
		else{
			MenuItem item =(MenuItem) menu.findItem(R.id.action_menu);
			item.setVisible(false);
 
		}
 
		return true;
	}
 
 
 
	// menue selected
 
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle presses on the action bar items
 
		SharedPreferences preferences = getApplicationContext().getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);  
		SharedPreferences.Editor editor = preferences.edit();
 
 
		switch (item.getItemId()) {
 
			case R.id.action_menu:
 
			 RundownListFragment f = (RundownListFragment) getSupportFragmentManager()
					.findFragmentById(R.id.rundown_list);
			 StoryDetailFragment f3 = (StoryDetailFragment) getSupportFragmentManager()
						.findFragmentById(R.id.story_detail_container);
			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
					 0, LinearLayout.LayoutParams.MATCH_PARENT);
			LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(
					0, LinearLayout.LayoutParams.MATCH_PARENT);
 
			LinearLayout.LayoutParams params2 = (LayoutParams) f.getView().getLayoutParams();	// for the following test
 
			if(params2.weight == 1.0f){
				params.weight = 0.0f;
 
			}
			else{
				params.weight = 1.0f;
			}
			f.getView().setLayoutParams(params);
 
			this.invalidateOptionsMenu();
 
 
			params3.weight = 1.0f;
			f3.getView().setLayoutParams(params3);
 
 
			return true;
 
 
// in activities menu file 
 
<item
 android:id="@+id/action_menu"
 android:icon="@drawable/ic_action_collection"
 android:showAsAction="always"
 android:title="@string/action_Menu"/>
 
 
 
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 360
Date Added: 2014-02-20 03:17:40
Last Modified: 2014-02-19 20:17:52

Web Analytics