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.