GridView vs. horizontal scroll

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

GridView vs. horizontal scroll

Postby bela » Tue Aug 11, 2009 9:03 am

Hi,

currently I'm working on an activity which should display some data in a GridView provided by a sqlite database. The table contains many columns, so I'm trying to make the GridView horizontally scrollable, so the user could easily navigate through the fields. I've already tried to use HorizontalScrollView, as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/panelcaption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp"
/>
<HorizontalScrollView
android:id="@+id/frame"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<GridView
android:id="@+id/grid"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:stretchMode="none" />
</HorizontalScrollView>
</LinearLayout>


However, the solution didn't work, on the emulator only one column showed up, I couldn't figure it out why. Does GridView support HorizontalScrollView anyway?

After that, I've tried to implement the horizontal scrolling programmatically, using the GridView.scrollBy() method:

public class CustomGridView extends GridView {

...

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_DPAD_RIGHT) {
this.scrollBy(100, 0);
}
else if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT) {
this.scrollBy(-100, 0);
}

return super.onKeyDown(keyCode, event);
}
}

In that case, I could navigate between the columns, however, it seems to me, that the scrolling and the onItemClick method doesn't work together properly: after scrolling, I've tried to click on a View in the Grid, but the onItemClick method always received wrong parameters. I suppose, the GridView doesn't refresh the value of the mFirstPosition (the position of the first child displayed) variable after scrolling its content. Or have I done something in a wrong way?

Any help on this topic would be very useful.

Thanks,
bela
bela
Freshman
Freshman
 
Posts: 2
Joined: Mon Aug 10, 2009 4:17 pm

Top

Postby arams » Wed Aug 12, 2009 5:56 am

try H.SCROLL in android 1.5
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 14 guests