ListView inside GridView not Scrolling? - android

I have a GridView that displays items, each item is a ListView.
the problem is that I can't scroll the ListView items, seems like the GridView is obtaining the focus or preventing it from the ListViews
is there a workaround for this ?
thanks
**
EDIT:
**
here's my activity layout
<GridView
android:id="#+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:verticalSpacing="35dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="300dp"
android:stretchMode="columnWidth"
/>
</LinearLayout>
each gridview item has the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/list"
/>
</LinearLayout>

set attribute android:scrollingCache="true" in your ListView
<ListView android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollingCache="true"
android:layout_weight="1" />

You cannot have a scrollable child view within a parent view that is scrollable. Google does not recommend it... and it's really messy. Read this
There have been people who've been trying to do a workaround (which doesn't look pretty), but I doubt it will work for you. But you can read it anyways and see if you can make it work for you. Enjoy.
One of the main reasons why it wont work is because of the way scrollable views handle touch. There's a method called dispatchTouchEvent() and onInterceptTouchEvent() that decides whether to intercept the touch event or pass it to it's children. For scrollable views, they will always intercept "swipe" movements. So it will never go to your children.
You can try to modify it, but if you think about it, how will you know if you're trying to scroll the parent or if you're trying to scroll the child? Imagine if the one of your scrollable children ends up taking the width of your screen, but then you want to scroll your parent, how will you manage that?
Summary:
it's not recommended .... if you really insist... then go ahead and write your own custom view to handle the logic. But i guarantee you it wont be pretty and will almost never work for all use cases.

Related

The bottom view is getting blocked by the top view

I have a really annoying problem with fitting two custom views to work together. I'm trying to display these two views in an android activity, but one of them takes the whole viewable space of the activity and the other is placed under it. The first view only uses a small part of the space and the rest is trasparent, but it only works when its width and height is at match_parent so the other view is displayed under it, but it is being blocked from receiving any touch events. here is how they looks like:
the xml code:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_app" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.fortysevendeg.android.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/example_lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="#00000000"
swipe:swipeActionLeft="dismiss"
swipe:swipeBackView="#+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="#+id/front"
swipe:swipeMode="both"
android:focusableInTouchMode="true"/>
</LinearLayout>
<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu
android:id="#+id/radial_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:padding="1dip" />
</FrameLayout>
What I'm trying to do is to be able to touch the bottom where the top view is transparent, and be able to touch the top view where it's not transparent. I tried arranging the xml in a different way but it keeps crashing, this is the only way it worked, but this problem appeared.
Links to the custom Views:
Radial-Menu-Widget: github.com/strider2023/Radial-Menu-Widget-Android
SwipeListView library: github.com/47deg/android-swipelistview
SwipeListView sample: github.com/47deg/android-swipelistview-sample
What I'm trying to accomplish here is something similar to Catch Notes app. If there are other ways, or other libraries you can suggest, it would be much appreciated.
Ok try this: copy the source code of SemiCircularRadialMenu.class in your project and modify
public boolean onTouchEvent(MotionEvent event)
Because this method always returns true and captures all touch events, so also the touch event for SwipeListView listener. I solved it in this way.
An old question, but others may find this answer helpful. Without modifying the source of your custom views, I don't think you can get the behavior you want. But getting the two custom views to work onto the same screen might be as simple as changing your root layout to a LinearLayout, adding weight to the inner layout, and setting the height of the second custom view to wrap_content. By having only one widget with a weight, it will get all the space left after the others are laid out. Here's your layout with the changes applied:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_app"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="100" >
<com.fortysevendeg.android.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/example_lv_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusableInTouchMode="true"
android:listSelector="#00000000"
swipe:swipeActionLeft="dismiss"
swipe:swipeBackView="#+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="#+id/front"
swipe:swipeMode="both" />
</LinearLayout>
<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu
android:id="#+id/radial_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="1dip" />
</LinearLayout>
If you need to height of the second view to be more expandable, you can wrap it in another LinearLayout with a weight and adjust the two weights to apportion the screen height between them. The individual weight values aren't special; it's their value relative to the sum of all the weights that determines how much height each one gets. I like to make my total values add up to 100 so I can think of the weights as percentages.

Trying to get textView to stick to gridView scroll

I have a fragment with a textView giving instructions, and below a gridView. I wanted for the textView to scroll upwards with the gridView. In other words: for textView to disappear off screen when gridView is scrolling.
My idea of how to accomplish this is to give the gridView a fixed height that would make the entire layout scrollable - including the textView. However, up until I cannot achieve this. Is there a way to do this?
Layout no scroll:
When scrolled:
Any help/advice would be appreciated.
My layout XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/LightGrey"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/chooseLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:text="#string/chooseLine"
android:textAppearance="?android:attr/textAppearanceLarge" />
<GridView
android:id="#+id/gridLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="130dp"
android:fitsSystemWindows="false"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:paddingTop="0dp"
android:stretchMode="columnWidth"
android:verticalSpacing="25dp" />
</LinearLayout>
Achieving this is is not going to be trivial. What you need is ListView's capability to add a header view, but unfortunately, GridView doesn't offer that functionality.
What I have done in the past to solve this problem is to convert the GridView to a ListView, and then add the header to the ListView. I created a wrapper adapter that takes the original adapter and combines a horizontal row's worth of grid cells into a single list row.
The tricky parts include: dynamically adapting the number of columns in a row based on the width of the screen, accounting for all combinations of view types within a row and remaining empty columns in the last row, and handling click interactions properly.
Put the whole LinearLayout in a ScrollView (How to use ScrollView in Android?) and for the GridView set android:layout_height="wrap_content"

Android expandable list with scrollview

Is it possible to have a custom expandable list view in android with scrollview?
ListView already have scrollView associated with it, you can use MergeAdapter to achieve this
I don't think any of you got his question right! He is asking about the "expandable" list view. Anyways I also seem to be having the same doubt.
I still think the answer is NO.
You may be able to use custom views and them inflate them into an already existent layout element which will give you the same effect. And I think that solution will be better.
ExpandableListView has its own listview. You don't have to integrate another listview on it. Notice that if you have a long list, vertical scroll is associated automatically.
combination of listview withing scrollview is not happening to be good option. if you will place any listview within scroll view the listview will not scroll. Its seeming to be officialy said by google android programmer that this will be a bad user experience.
Of course, combination of expandable listview withing VERTICAL scrollview is not happening to be good option, but using it within HorizontalScrollView works impressive. I use this method in my program. User can horizontally scroll long strings.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
android:id="#+id/RelativeView01"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<Button
android:id="#+id/btnSaveSelection"
android:layout_alignParentLeft="true"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:text="#string/SaveSelection"
android:focusable="true"
android:background="#drawable/android_button"
android:onClick="myClickHandler14" />
.........
<HorizontalScrollView
android:id="#+id/HorizontalScrollView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollbars="horizontal|vertical"
android:layout_above="#id/button_add_group"
android:layout_alignParentTop="true">
<LinearLayout android:id="#+id/LinearLayout02"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content">
<ExpandableListView android:id="#+id/android:list"
android:layout_width="750px"
android:layout_height="wrap_content"
android:groupIndicator="#android:color/transparent" />
<TextView android:id="#+id/android:empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:text="#string/no_data"/>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>

Getting a button to scroll into view at the bottom of a GridView on Android

I am trying to port an existing iPhone application to android. I wish to have a button scroll into view at the bottom of a GridView to enable the user to load more data from the server. Presently, my solution simply fixes a button at the bottom of the screen instead of having it scroll into view.
Here is my layout code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="70dp"
android:numColumns="auto_fit"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#000000"
/>
<Button
android:id="#+id/load_more"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load More"
/>
</LinearLayout>
Fixing the button at the bottom of the screen won't work because I plan on placing an ad at the bottom.
Can anyone either explain conceptually how to get a load more button to scroll into view, or point me to some sample code, OR tell me why this is not idiomatic to Android and what other UI convention it uses to load more data in a GridView?
Thanks!
You can place a ScrollView inside your main LinearLayout. A ScrollView can only have one direct child, though, so you'll need to put another LinearLayout inside of it which would then contain your GridView and Button.
I had a similar problem with scrolling a GridView and after refreshing the underlying data, noticing that the scoll was not reset to the beginning. I solved it with the following code fragment
gvKeys.setSelection(0);
I'm guessing that if you know the number of items in your grid, N, that the following will work:
gvKeys.setSelection(N);

How to scroll programatically a ScrollView?

I have a little problem with a ScrollView. I have a layout for an activity which is made with a ScrollView. This scrollview contains two ListViews.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootViewGroup" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="vertical">
<LinearLayout android:orientation="vertical"
android:gravity="top" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#drawable/cmb_bg">
<ListView android:id="#+id/accountsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="none" />
<ListView android:id="#+id/cardsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="none" />
</LinearLayout>
In the onCreate method of my activity I compute ListViews height according their contents.
During execution, on activity launch, ScrollView is already scrolled a bit.
So I tried, at the end of onCreate to call method scrollTo(0, 0), but it does not change anything.
Any ideas?
AHHH!!! Remove ScrollView and leave only ONE ListView in your activity. It's not intended to work this way
.If you want to have different content in your ONE listView - modify your adapter, or change the UI
But never, ever put different scrollable containers on the same screen/inside each other
here is a related post.
http://groups.google.com/group/android-developers/browse_thread/thread/e7c8df374fe31733#
In theory you can slap two listview on the screen, but expect things to be weird. And i would really redesign it with with either separators or expanders or just with one ListView.

Categories

Resources