Scrolled but till header visible in listview in android - android

I create a listview and that listview has a header. I use addHeaderView() method. But when i scroll down in listview the scrollbar vanishes. Is there any way to avoid this i.e i want to show the header all the times, if scrolled still it will show.

To do that you can't do that with the addHeaderView() method.
If you want to place a header on top you should place that in the layout, something like this.
<?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/titleBarText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>

The widget is behaving as intended. For what you need, you need to create a relativelayout with TextView at top followed by listview. The textview would act as the header and be static irrespective of your scroll.

Related

Edit Text and Text View not visible when ListView is set in Android

here my xml layout of my Android app (where I show all of my contacts)
<?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/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="5dip"
android:text="Scegli il contatto:"
/>
<EditText
android:id="#+id/editTextSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
I fill ListView using a custom Adapter.
But textView and Edit Text are not visibile. I want to show in particular edit text where users can write initial letters of his contacts name)
Suggestions to get them visible?
I fill ListView ... But textView and Edit Text are not visibile.
If you can only see a ListView then it appears you're using a ListActivity and forgot to call setContentView(). So you aren't actually using your layout... you only see ListActivity's default ListView.
That said, your XML code will work, but here are some quick notes:
As I stated in my comment, the TextView might be hidden depending on what type of Activity or Fragment you are using:
A ListActivity will automatically bind the #+id/android:empty and #+id/android:list Views, so the "empty" TextView is only shown when the ListView is empty.
An Activity won't recognize #+id/android:empty on its own. All the Views should be visible.
fill_parent is deprecated, simply use match_parent
Setting a ListView's height to wrap_content forces the Adapter to draw the ListView multiple times... with your layout I recommend using match_parent.
I'd say it is visible pretty fine with your layout. But anyway, I'd make listview declared that way:
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
so it will take all the remaining free space

How to add an explanatory text before a list view in android?

I have a list view but at the begining i want to place a piece of text that will help the users to understand what't the purpose of that list. After that i want to display the list and i want to be srollable. The scroll i know how to do it, but the text part no. I've tryed to make two layouts, one for the text and another for the list, but my xml instantly becomes fill with errors.
That's my xml
<?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"
android:background="#drawable/legislatie1"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="wrap_content"
android:layout_height="600dp"
android:layout_alignParentRight="true"
android:drawSelectorOnTop="true"
android:textSize="10pt" >
</ListView>
</RelativeLayout>
You can use a static TextView above the ListView if you choose, but it will not scroll with the ListView. An alternative is to add a Header to your ListView, which will scroll with the list. Header Tutorial

How can I set a footer in an android listview to dynamically stretch to the bottom?

I searched already but unfortunately found no real solution to this. I have added a footer to a listview with:
View footer = getLayoutInflater().inflate(R.layout.listfooter, null);
listview.addFooterView(footer);
The xml for the footer looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#FFFFFFFF"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="#ee222222"
>
<TextView
android:id="#+id/info"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Test Test Test"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
It does display a footer only as a single line
I change the number of rows in the list dynamically but I want the footer to always fill the rest of the listview if there are not enough items in it.
How can I do this?
Edit: I added an image, the left is how it is right now and the 2 on the right is what I want.
I can say the best solution can be for this problem is.
1) Create a XMl layout which must have hierarchy like this.
<Liniear Layout>
<ScrollView>
<LinearLayout>
<ListView>// add your list data here.
<\ListView>
<TextView><TextView>// for footer text
<\LinearLayout>
<ScrollView>
<LinearLayout>
Please let me kno if anything, I hope this approach will work as I tried it myself.

Overlay TextView at bottom of ListView

I have a ListView that is being populated with a custom adapter. I have a pretty basic layout for each row of the the ListView (not even sure if this is applicable to my question):
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/BaseStyle"
android:orientation="vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
>
<TextView
android:id="#+id/text"
style="#style/BaseStyle.Title"
/>
</RelativeLayout>
I'd like to overlay a single TextView at the bottom of the ListView, but not entirely sure how as working with Android layouts can be an exercise in futility. :)
Wrap your main layout with a FrameLayout and put the view that you want to be in overlay as last child.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_height="match_parent"
android:layout_width="match_parent">
...
your ListView
...
your text view (it is gonna be on top of your layout)
</FrameLayout>
From your description I am not sure that this is what you are looking for, you should give some more info in your question, let me know.
If instead you are just talking about the TextView inside each list item then you just need to specifiy the alignment in your text view:
android:layout_alignParentBottom="true"

Add ImageView to a ListActivity

I would like to add an ImageView under my ListView in my ListActivity. So that when the user scrolls to the end of the list, the ImageView shows.
I can't seem to get my layout correct. Either the ImageView is not displayed at all, or if I use layout_weights, then both the ListView and ImageView get 50% of the screen. Any ideas how I can get what I want? Thanks.
<?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" >
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/list_no_items" />
<ImageView
android:id="#+id/instruct_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/instructions"/>
</LinearLayout>
Unfortunately I don't think what you want to accomplish is easily done with standard Android layouts. You can't have a ListView within another ScrollView.
You could use the ListView footer to position the ImageView below the ListView.
Or, you could try to add the ImageView as the last row in the ListView. To do this, override the getView method of the adapter and return the ImageView if it is the last row.

Categories

Resources