1

I tried to implement multiple gridView within a scrollview so that all girdview has only one scrollbar. I used two gridView. My layout is like that:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

<com.example.ExpandableHeightGridView
    android:id="@+id/gridView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:horizontalSpacing="2dp"
    android:isScrollContainer="false"
    android:numColumns="2"
    android:stretchMode="columnWidth"
    android:verticalSpacing="20dp" />


    <com.example.ExpandableHeightGridView
    android:id="@+id/gridView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:horizontalSpacing="2dp"
    android:isScrollContainer="false"
    android:numColumns="1"
    android:stretchMode="columnWidth"
    android:verticalSpacing="20dp" />

 </LinearLayout>

</ScrollView>

I used This like for "ExpandableHeightGridView"

and in main activity i used this:

    final ExpandableHeightGridView gView1 = new ExpandableHeightGridView(this);
gView1.setNumColumns(2);


ArrayList<HashMap<String, String>> list_of_wordmeanings = new ArrayList<HashMap<String, String>>();

Cursor mCursor = mDbHelper.getWord(value_of_category_id);
for (int i = 0; i < mCursor.getCount(); i++)
{
    mCursor.moveToPosition(i);

    HashMap<String, String> hm = new HashMap<String, String>();   
        String column1data = mCursor.getString(0).toString();
        String column2data = mCursor.getString(1).toString();
        String column3data = mCursor.getString(2).toString();
             hm.put("key_word",column1data);
             hm.put("key_meaning",column2data);  
             hm.put("key_translitaration",column3data); 
        list_of_wordmeanings.add(hm);
}

   // Keys used in Hashmap
        String[] from = { "key_word","key_meaning","key_translitaration" };
        int[] to = { R.id.txt1,R.id.txt2,R.id.txt3};     // Instantiating an adapter to store each items
        // R.layout.listview_layout defines the layout of each item
        SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), list_of_wordmeanings, R.layout.grid_layout, from, to);
     // Setting the adapter to the listView
        gView1.setAdapter(adapter);
        gView1.setExpanded(true);


        gView1.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {
                // TODO Auto-generated method stub


                HashMap<String, String> hash = new HashMap<String, String>();
                hash=(HashMap<String, String>) gView1.getItemAtPosition(position);

                String english_word=hash.get("key_word");
                String native_word=hash.get("key_meaning");

                 // Show Alert 
                Toast.makeText(getApplicationContext(),
                 "  gridViewValue : "+native_word , Toast.LENGTH_LONG)
                  .show();

            }
        });

It doesn't work properly.

Community
  • 1
  • 1
nobody
  • 31
  • 2
  • Why a new question for the [same problem](http://stackoverflow.com/questions/29762578/two-gridview-with-one-scroll-in-android). Rather update your previous question with the updated details! – Paresh Mayani Apr 21 '15 at 05:52
  • A`ListView` or a `GridView` never works inside `ScrollView` like this. – Anshul Tyagi Apr 21 '15 at 05:54
  • @nobody delete this question and update your previous question with this details! – Paresh Mayani Apr 21 '15 at 05:55
  • you can follow this question [how to set Multiple gridview in same layout in android?](http://stackoverflow.com/questions/7401853/how-to-set-multiple-gridview-in-same-layout-in-android) – BBdev Apr 21 '15 at 05:56

1 Answers1

0

In GridView2, you restricted with Number of Columns as 1. Check it.

The purpose of GridView is to implement multiple columns.

Piyush
  • 18,895
  • 5
  • 32
  • 63
Harish
  • 63
  • 6
  • In gridView2 column should be 1 it is no problem,My problem is that it shows only one data(row).Any other idea?? @Harish – nobody Apr 21 '15 at 06:19