Expandeble list view Always scroll to bottom issue - android

I created simple Application, I have Expandable List View which display the dictionary words.
This Expandable list view works almost properly but when I touch to any of the word, It
scrolls to bottom. Any help will be appreciated.
This is my Xml File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/dicrellis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ExpandableListView
android:id="#+id/expandable_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:transcriptMode="alwaysScroll"/>
</RelativeLayout>
</RelativeLayout>
and this my java Code...
mExpandableList = (ExpandableListView)findViewById(R.id.expandable_list);
mExpandableList.setAdapter(new MyCustomAdapter(Dictionary.this,arrayParents));
mExpandableList.setOnItemClickListener(this);

Try this solution.
<ExpandableListView
android:id="#+id/expandable_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:transcriptMode="normal"/>
Just replace android:transcriptMode="alwaysScroll" from this android:transcriptMode="normal"

android:transcriptMode="alwaysScroll"when using this, the list will automatically scroll to the bottom, no matter what items are currently visible.
For other options see transcriptMode

Related

Why is listview items length set by the first item

I created horizontal scrollable listview. And I can populated from db without any problem. The problem is; the entire length of the items are setted to the length of the first item.
Like this
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
</RelativeLayout>
Simple solution to this problem is to use Recyclerview instead of List View.
Adding HorizontalScrollview to LinearLayout will not work.
I have already tried many solutions posted here
after a lot of search I come to this point my solution was Recyclerview.
And from here i learned,How to use this.
You need to make listView height match the parent
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</HorizontalScrollView>
</RelativeLayout>

Forcing Android Fast Scroll Bar on ListViews to draw within padding

I am interested in creating a screen composed of a transparent header and a listview that scrolls behind the header. I have this working with one flaw; the FAST scroll bar also draws underneath header.
For some reason, the fastscrollbar doesn't seem to respect the scrollbarStyle applied to the list view. You'll notice in the image below that the normal scroll bar works fine, but the powerscroll bar is behind the transparent header.
Unfortunately the listviews I am using will often have hundreds of items, so the fastscrollbar is a necessity. Is there some way to set the "fastscrollStyle" that is not documented? I am open to any suggestions! Thank you.
Here is the layout XML for reference:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/myListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipToPadding="false"
android:fastScrollEnabled="true"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay"
android:paddingTop="50dp"/>
<TextView android:text="My Header"
android:gravity="center"
android:background="#8fff0000"
android:layout_width="fill_parent"
android:layout_height="50dp"/>
</RelativeLayout>
This was fixed in KitKat for ListView, however GridView still appears to exhibit this problem. Google?
The best solution is to separate your listview from the other layouts, where the main relativelayout view is the parent and other layouts are the children.
EX.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id"#+id/layoutHeader"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true">
<TextView android:text="My Header"
android:gravity="center"
android:background="#8fff0000"
android:layout_width="fill_parent"
android:layout_height="50dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="+id/layoutHeader">
<ListView
android:id="#+id/myListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipToPadding="false"
android:fastScrollEnabled="true"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay"
android:paddingTop="50dp"/>
</RelativeLayout>
</RelativeLayout>
This bug appears to be fixed in 4.4. In older versions however, there appears to be no known workaround other than leaving padding at 0.

Adding Expandable List View and a normal list View in android

I want to add a Expandable List View and a normal list view in this XML layout when I tried to show the both Expandable List View and a normal list only showing the expandable listview.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical" >
<ExpandableListView
android:id="#+id/expandableListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ExpandableListView>
<ListView
android:id="#+id/list_evevnt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
I am afraid you can't use both lists like that ... The way I see it, you have 2 options:
Either you'll add the second listview items in the first expandablelistview by extending the adapter class: for each item in this expandable that belongs to second listview, you'll have to set child count to zero so you will not have anything to expand. In ExpandableListAdapter#getGroupView() you can return the View from second listview adapter getView
There is a project created by Mark Murphy (aka CommonsWare), CWAC MergeAdapter that allows merging different listview and views in a single UI component. Since ExpandableListView is a ListView, then in theory it should work. I used this project successfully but without ExpandableListViews... If it works with these, please let me know
I hope it helps!
Try this......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidrientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ExpandableListView
android:id="#+id/expandableListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</ExpandableListView>
</LinearLayout>
<ListView
android:id="#+id/list_evevnt"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Use This
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:weigthSum="1" >
<LinearLayout android layout_weight=0.5
android:layout_height="0dp"
android:layout_width="fill_parent">
<ExpandableListView
android:id="#+id/expandableListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ExpandableListView>
</LinearLayout>
<LinearLayout android layout_weight=0.5
android:layout_height="0dp"
android:layout_width="fill_parent">
<ListView
android:id="#+id/list_evevnt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout>
</LinearLayout>
you can't put 2 list views like that because when you scroll only the first list view will be scrolled .try changing your layout_height of expandablelistview to a specific dip it may help.
Try assigning a android:layout_weight to the ListView element as well. I think you have to have one since you set one for the ExpandableListView.
I used this tutorial for expandable list view, may this will helpful for you. good luck.
I think you should assign
android:layout_width="0px" for both views and assign
android:layout_weight for listview as well.
layout_weight won't work properly without layout_width set to 0px

Android, How to add ScrollView into screen which has some list items?

in my activity, i have three lists. after running the application, the screen is not scroll-able. i can scroll the list which is on top of others but i can't scroll the whole of page. I tried to add ScrollView into my xml layout but lint says that "The vertically scrolling ScrollView should not contain another vertically scrolling widget (ListView)".
How to make my screen scrollable?
Try this way
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="#+id/GlobalLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="#+id/ListView1"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
<ListView android:id="#+id/ListView2"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
<ListView android:id="#+id/ListView3"
android:choiceMode="multipleChoice"
android:layout_height="100dip"
android:layout_width="fill_parent" />
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</ScrollView>
Scrollview supports one child layout so make the listview inside the scroll so you will get what you want.
It doesn't work because android don't know with which view he should scroll, so putting a listview in a scrollview its not a bright idea.
try to use visibilty attribute, use to HIDE the view that you finich to work with and set VISIBLE the new.
or use one ListView and try to populate and remove items after finishing and starting an instruction.
hope that help you
What you can do is that you can add header and footer into your list view by inflating them. Create three xml layououts and add them in listview using header and footer.
View headerView = View.inflate(this, R.layout.layout_name, null);
lv.addHeaderView(headerView);
use it before setting adapter. lv is listview.

Android delete from listview [duplicate]

I have listview that contain checkbox and an image when the checkbox is clikced I show a button at bottom of the screen that perform deletion, but when listview height more ,then the listview some portion move under the button ,so I need an alternative option for delete can anyone help me, I except something like menu?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_centerHorizontal="true"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="#+id/DelPhto"
android:text="Delete" android:layout_alignParentBottom="true" />
<ListView
android:layout_width="280dp"
android:layout_height="fill_parent"
android:id="#+id/list_pictures"
android:layout_alignParentTop="true"
android:layout_above="#+id/DelPhto" />
</RelativeLayout>
Do you mean you wish for the delete button to be always visible even when the list contents are larger than the list control?
If that's the case try setting the layout_weight of your ListView to 1 and see if that solves your problem.
Put ListView in ScrollView (so one will be able to scroll entire list), like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/listView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
android:headerDividersEnabled="true">
</ListView>
</ScrollView>
</LinearLayout>
I have had a similar issue in the past. I found that using a relative layout and defining the button before the list solved my issues. Lets consider the following.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/someButtonId"
android:background="#drawable/gray_button"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:text="#string/some_button_value"
android:textColor="#color/button_text"
/>
<ListView
android:id="#+id/someList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/someButtonId"
/>
</RelativeLayout>
Here I have defined a Relative layout, the layout will occupy the full screen's width and height. I then place the button on the bottom of the RelativeLayout. My expectation is that the list will be placed above the defined button, and fill the remainder of the screen with list contents. Because we are telling the list View to be placed above the button, it will never grow large enough to cover the button causing the list view to mask the button clicks from the user.
hope this helps.

Categories

Resources