-1

I'm new android..my english little bit:( I want develop multi pane app. Two fragments "Gridview" and "Full screen" I know multi pane, but i dont know Gridview and Full screen in multi pane. Because all samples for ListView. help me please

this app good for me but too complex= http://www.codeproject.com/Articles/779293/Building-Dynamic-UI-for-Android-Devices

SiBemol_2
  • 3
  • 5

1 Answers1

0

Its a simple implementation if i understand your question correctly

------------- Creating GridView ------------

  1. For GridView you need an adapter for your GridView Object and images for columns, an example using country list and flag images,

Create drawable folder inside res and add country flag images inside drawable folder

  1. Create gridlayout.xml in res/layout

       <RelativeLayout  
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:background="@drawable/border"
        android:padding="5dp">
    
        <ImageView 
        android:id="@+id/gridimage" 
        android:layout_height="65dp" 
            android:layout_width="65dp" 
            android:src="@drawable/icon" 
            android:layout_alignParentTop="true" 
            android:layout_centerHorizontal="true">
        </ImageView>
    
        <TextView 
            android:id="@+id/gridtext"
            android:text="TextView" 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_below="@+id/imageView1" 
            android:layout_marginTop="2dp"
            android:layout_centerHorizontal="true"
            android:textSize="18sp"
            android:ellipsize="marquee"></TextView>
    
    </RelativeLayout>
    
  2. Create gridrow.xml in res/Layout folder

    <GridView 
        android:id="@+id/gridView1" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:numColumns="auto_fit"
        android:horizontalSpacing="10dp"
        android:verticalSpacing="10dp">
    </GridView>
    

  3. Create GridAdapter.java class

    public class GridAdapter extends BaseAdapter { 
        private ArrayList<String> CountryList;
                private ArrayList<Integer> CountryFlag;
                private Activity activity;
                public GridAdapter(Activity activity,ArrayList<String> CountryList, ArrayList<Integer> CountryFlag){
    super();this.CountryList = CountryList;
                this.CountryFlag = CountryFlag;
                this.activity = activity;}
        @Override
            public int getCount() {
                return CountryList.size();
            }
    
            @Override
            public String getItem(int position) {
                return CountryList.get(position);
            }
    
            @Override
            public long getItemId(int position) {
                return 0;
            }
    
            public static class ViewHolder
            {
                public ImageView imgViewFlag;
                public TextView txtViewTitle;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                ViewHolder view;
                LayoutInflater inflator = activity.getLayoutInflater();
    
                if(convertView==null)
                {
                    view = new ViewHolder();
                    convertView = inflator.inflate(R.layout.gridview_row, null);
    
                    view.txtViewTitle = (TextView) convertView.findViewById(R.id.gridtext);
                    view.imgViewFlag = (ImageView) convertView.findViewById(R.id.gridimage);
    
                    convertView.setTag(view);
                }
                else
                {
                    view = (ViewHolder) convertView.getTag();
                }
    
                view.txtViewTitle.setText(CountryList.get(position));
                view.imgViewFlag.setImageResource(CountryFlag.get(position));
    
                return convertView;
            } 
    

    }

    1. Create Fragment GridViewActivty

    public class GridViewActivty extends Fragment { private ArrayList CountryList = new ArrayList(); private ArrayList CountryFlag = new ArrayList(); private GridView mygrid; private GridAdapter adapter; private Context context; public GridViewActivty(){} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.gridlayout.xml, container, false);

              CountryList = new ArrayList<String>();
              CountryList.add("South Africa");
              CountryList.add("Spain");
              CountryList.add("Canada");
              CountryList.add("China");
              CountryList.add("France");
              CountryList.add("Germany");
              CountryList.add("Iran");
              CountryList.add("Italy");
              CountryList.add("Japan");
              CountryList.add("Korea");
              CountryList.add("Mexico");  
              CountryList.add("Netherlands");
              CountryFlag = new ArrayList<Integer>();
                  CountryFlag.add(R.drawable.southafrica);
                  CountryFlag.add(R.drawable.spain);
                  CountryFlag.add(R.drawable.canada);
                  CountryFlag.add(R.drawable.china);
                  CountryFlag.add(R.drawable.france);
                  CountryFlag.add(R.drawable.germany);
                  CountryFlag.add(R.drawable.iran);
                  CountryFlag.add(R.drawable.italy);
                  CountryFlag.add(R.drawable.japan);
                  CountryFlag.add(R.drawable.korea);
                  CountryFlag.add(R.drawable.mexico);
                  CountryFlag.add(R.drawable.netherlands);
                 adapter = new GridAdapter(this.getActivity(),CountryList, CountryFlag);
    
            mygrid = (GridView)rootView.findViewById(R.id.gridview1);
    
            mygrid.setAdapter(adapter);
            mygrid.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener()
            {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                        long arg3) {
                    // TODO Auto-generated method stub
    
                }
            }
                    );
            return rootView;
    
            }
    
    }
    

    ----------- Creating Full Screen --------
    
  4. Create fullscreen.xml inside Layout Folder

        <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </RelativeLayout>    
    

    >

  5. Create FullScreen.java Fragment

     public class Fullscreen extends Fragment{    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle 
             savedInstanceState)    
    { View rootView = inflater.inflate(R.layout.fullscreen.xml, container, false);
             requestWindowFeature(Window.FEATURE_NO_TITLE);
    
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    
             WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
                }
    
            return convertView; }
    
  • i think stackoverflow codeblock has a problem or is it my code that doesn't want to be in form @codeblock ? –  Jan 31 '15 at 21:59
  • thanks for your help..but how i make these fragments into Multi pane layout (tablet, handset). I hope I could explain better. – SiBemol_2 Jan 31 '15 at 22:53
  • So how do I put this fragments in multi pane layout(tablet handset)? as this= http://developer.android.com/guide/practices/tablets-and-handsets.html – SiBemol_2 Jan 31 '15 at 23:09
  • i will check on my codes 2 years ago i coded a sliding multipane fragments, but you said you knew multipane? –  Jan 31 '15 at 23:23
  • I know multi pane with ListView but I dont know with GridView.. Fragment1 Grirview Fragment2 Full Screen.In Dual Pane. but I dont know how – SiBemol_2 Feb 01 '15 at 08:40
  • this app good for me but too complex= http://www.codeproject.com/Articles/779293/Building-Dynamic-UI-for-Android-Devices – SiBemol_2 Feb 01 '15 at 11:16
  • Here is Multipane source code - https://github.com/Altiano/MultipaneFragments and here is a video link for in case if you get lost https://www.youtube.com/watch?v=8Rjkv2-saDk , get back to me if you get any problems with this –  Feb 01 '15 at 17:32
  • first **thanks** your helps, really.. I'm not use in **eclipse** yet.no errors in eclipse but stopped in emulator..how can i change **gradle project** to **eclipse project**? – SiBemol_2 Feb 01 '15 at 22:31