3

I have a GridView with 4 columns, when one is selected, I wanted to dynamically add a whole row underneath the selected cell, and inflate a layout in it, so that I could add some information about the selected cell. Is there anyway to do that? Or maybe, is there a way to split a view in half, then glue it back together when done? Sounds crazy.

Essentially, I'm looking for something you can find on iTunes 11 (see the picture below).

enter image description here

Jean-Paul Manuel
  • 546
  • 2
  • 12
  • 29

2 Answers2

0

Yeah. You can do that. the xml file where you defined grid view, below that define one linear layout too and make it invisible by adding following code:

android:visibility="invisible"

On click the GridView, inflate that layout and set its visibility and use following java codes:

LinearLayout l2=(LinearLayout)findViewById(R.id.linearLayout);
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);           
View detailView = inflater.inflate(R.layout.yourInformationLayoutOfGridItem, l2, false);

for set visibility true/false by java code:

Visibile: l2.setVisibility(0);
Invisible: l2.setVisibility(4);
Rohit
  • 490
  • 3
  • 15
  • But wouldn't this inflate a Layout underneath the whole GridView? I need something that would inflate the Layout underneath that specific cell, while pushing the rest of the rows of the GridView downwards. – Jean-Paul Manuel Feb 07 '13 at 08:05
  • Yeah. you are right. I got it. You want it like google Image seach. I am not sure if tableRow can help instead of GridView. – Rohit Feb 07 '13 at 08:21
0

The Solution to your question is to simple use TabHost widget:

The XML file to that is as below:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>

         <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="match_parent" />

    </LinearLayout>
<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>

</TabHost>

And The java code for that is as below:

public class AndroidTabLayoutActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();

        // Tab for Photos
        TabSpec photospec = tabHost.newTabSpec("Photos");
        photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
        Intent photosIntent = new Intent(this, PhotosActivity.class);
        photospec.setContent(photosIntent);

        // Tab for Songs
        TabSpec songspec = tabHost.newTabSpec("Songs");
        // setting Title and Icon for the Tab
        songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.icon_songs_tab));
        Intent songsIntent = new Intent(this, SongsActivity.class);
        songspec.setContent(songsIntent);

        // Tab for Videos
        TabSpec videospec = tabHost.newTabSpec("Videos");
        videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon_videos_tab));
        Intent videosIntent = new Intent(this, VideosActivity.class);
        videospec.setContent(videosIntent);


        // Adding all TabSpec to TabHost
        tabHost.addTab(photospec); // Adding photos tab
        tabHost.addTab(songspec); // Adding songs tab
        tabHost.addTab(videospec); // Adding videos tab
    }

Hope this works fine for you.. And hope this is what you asked for.

Ankit Dhadse
  • 1,566
  • 1
  • 15
  • 19
  • This is for doing a Tab Layout, I'm asking about inflating a Layout in between 2 rows of a GridView. Totally different things. – Jean-Paul Manuel Feb 07 '13 at 08:17
  • Are you saying that you want to add view dynamically... u can use ExpandableListView for that..!! – Ankit Dhadse Feb 07 '13 at 08:23
  • I'm saying I want to add a view as a row instead of an item, but while keeping the rest of the GridView as a 'grid' of ImageView for example. Moreover, an ExpandableListView is a whole other thing, you can't even have columns in that. – Jean-Paul Manuel Feb 07 '13 at 08:40