Why is listview items length set by the first item - android

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>

Related

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

Expandeble list view Always scroll to bottom issue

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

Android List wrap content

I am creating some TextView, ImageView, HtmlView dynamically and adding it in following layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/ad_space"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#drawable/navigation_bar"
android:visibility="gone" >
</LinearLayout>
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ScrollView
android:id="#+id/quiz_scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/quizView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/answer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/quiz_scroll_viewTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/quizViewTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/answer_layoutTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
</ViewFlipper>
</LinearLayout>
In QuizView I am adding some question related views at runtime, and for answers I am creating one list view runtime and adding to answer_layout. I am using BaseAdapter to create ListView runtime based on situation.
But my ListView is not showing all content, its showing only first cell.
I have adding ListView like this.
ListView ansList = new ListView(Test.this);
ansList.setAdapter(adapter);
ansList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
ansCellLayout.addView(ansList);
it display only one list cell.
if I set some int value for height then its show all list contains.
ansList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 600));
But I cant Hardcode list view height as my contant is dynamic.
How to make list view as a WRAP_CONTENT in this scenario ?
According to the Android developers as seen in this Google I/O 2010 video , the ListView's height cannot be set to wrap_content. And when it is , the first three child elements are considered for the height. The others are simply not included.
Try setting the ListView's height at runtime. Or even better set it to FILL_PARENT.
From the documentation a ListView is
A view that shows items in a vertically scrolling list
So it's not supposed to be used with WRAP_CONTENT but rather to have a fixed height and scroll content inside it.
You'd better use a vertical LinearLayout for that purpose.

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.

Problem with the display of custom listview (webview in my listview)

I am having an issue that make me crazy
I have a listview with WebView inside. So I created a custom listview.
The WebView forbid me to click so I created a webviewclicklistener.
My problem was that when I display some images, my webviews are "shaking" as if it wants to load the image a thousand times.
In fact I discovered that the height size of some elements change like every seconds, that give a feeling of shake.
The only way I found to fix it is to give a layout:height value for my listview.
My new problem is that when I put for exemple 600dip, I have a scrollbar, but I can't look at the end of my listviews.
If I put like 1000dip, I don't have scroll bar and I can't see the end of my list neither.
Here is my layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#drawable/woodbackground"
android:layout_weight="1">
<TextView android:background="#android:color/transparent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Question" android:textSize="30px"></TextView>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<WebView android:id="#+id/wvplquestion" android:layout_height="wrap_content"
android:layout_width="fill_parent"></WebView>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_weight="1">
<TextView android:background="#android:color/transparent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Select Answer" android:textSize="30px"></TextView>
<ListView android:id="#+id/lvquestion" android:layout_width="fill_parent"
android:layout_height="600dip" android:prompt="#string/selectp" />
</LinearLayout>
And my custom listview layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="3dip">
<WebView android:id="#+id/weblistview" android:layout_width="fill_parent"
android:layout_height="wrap_content"></WebView>
Thanks for your help
maybe you can try to change your listview layout height. Instead of wrap content, put a fixed height. I don't know if it will be working, but you can try it. I'd a problem similar to yours and I solved it like this.
I hope it will work. Good luck ;)
Seems it mostly happens when several webviews contained into one scrollview. Seems at least first webviews should have fixed height.

Categories

Resources