Buttons below the ListView - android

I have the listView with set of items. And I want to add 2 buttons below the list. But if I do like this:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fileManager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:background="#000000"
android:id="#+id/fileManagerList"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
<CheckedTextView
android:id="#+id/checkedTextItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:clickable="true"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:textColor="#000000"
android:paddingLeft="10dip"
android:paddingRight="6dip"
android:typeface="sans" android:textSize="16dip"/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fileManager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignBottom="#+id/fileManagerList">
<Button
android:id="#+id/attachFiles"
android:layout_width="200dp"
android:layout_height="55dp"
android:background="#007FFF"
android:gravity="center|center"
android:text="Attach files"
android:layout_alignBottom="#+id/fileManagerList"
android:textColor="#FFFFFF"
android:textSize="18dp"
android:textStyle="bold" />
<Button
android:id="#+id/cancelFiles"
android:layout_width="82dp"
android:layout_height="55dp"
android:background="#838B83"
android:gravity="center|center"
android:layout_alignRight="#+id/attachFiles"
android:layout_alignBottom="#+id/fileManagerList"
android:text="Do not attach"
android:textColor="#FFFFFF"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
my buttons displaying in each row of ListView. I tried do it the same way but using RelativeLayout, but I get correct list, buttons were in the bottom, but they overlay the last item of the list. How can I implement this?

Try this Layout, You can achieve your goal using the below XML Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relRingtone"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/fileManagerList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:contentDescription="#string/ringtone"
android:layout_marginLeft="3dip"
android:textSize="2dp" />
<LinearLayout
android:id="#+id/closecalmlayout"
android:layout_below="#+id/fileManagerList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1.0" >
<Button
android:id="#+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="5dip"
android:layout_weight=".50"
/>
<Button
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:layout_weight=".50"
/>
</LinearLayout>
</RelativeLayout>
Hope it helps.

This is because you are using #+id everywhere, wherever you are referring any id. Ex.:
android:layout_alignBottom="#+id/fileManagerList"
Use "#id/" instead.
And also, try:
android:layout_below="#id/fileManagerList" // Add this attribute in button.

Related

Android - Two buttons in same line filling the whole width

I have a little problem defining a Relative Layout. I have a List View with scroll and two buttons always visible at the bottom of the list view. I just would like my two button have 50% of the width, filling the line. This is my code:
<?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"
android:orientation="vertical" >
<Button
android:id="#+id/testbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Save" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/testbutton"
android:text="Cancel"/>
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/LstPeriodOptions"
android:layout_alignParentTop="true"
android:layout_above="#id/testbutton" />
</RelativeLayout>
I tried to introduce the buttons in a Linear Layout and give the gravity=1 with width=0dp but in that case the ListView dissapears. Could you help me please?
Sorry for my english. This is the result I would like to have:
Thanks a lot, best regards.
EDIT: This is what I tried with Linear Layout:
<?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"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/container" >
<Button
android:id="#+id/testbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Guardar" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/testbutton"
android:text="Cancelar"/>
</LinearLayout>
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/LstPeriodOptions"
android:layout_alignParentTop="true"
android:layout_above="#id/container" />
</RelativeLayout>
Did you try with your LinearLayout in this way because this should work. Note all of the property changes. Since I don't know how yours was, I can't point out all of the differences.
<?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" >
<LinearLayout
android:id="#+id/btnLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/testbutton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/cancelButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"/>
</LinearLayout>
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/LstPeriodOptions"
android:layout_above="#id/btnLL" />
</RelativeLayout>
Try out as below to set your button in LinearLayout and set it below your ListView:
<LinearLayout
android:id="#+id/laytbtns"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#+id/LstPeriodOptions" >
<Button
android:id="#+id/testbutton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="Save"/>
<Button
android:id="#+id/cancelButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
Try this..
<?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="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/LstPeriodOptions"
android:layout_above="#id/testbutton" />
<LinearLayout
android:id="#+id/laytbtns"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#+id/LstPeriodOptions" >
<Button
android:id="#+id/testbutton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:text="Save"/>
<Button
android:id="#+id/cancelButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>

Simple Android layout issue

I want to do something very simple. I want a layout that has a spinner at the top, followed by a List View, followed by a Linear Layout at the very bottom that wraps some buttons. I want the List View to expand to fill the space between the spinner and the buttons, no matter how big the window is. I have been trying this with a Linear Layout wrapping all three elements and I have tried every combination of Wrap Content and Fill Parent for Layout_Height that I can think of but unless I hard code the List View Layout_Height to say 300 dip, the buttons are pushed off the screen. I know that there must be an easy way to do this but I am at my wits end. I have tried everything I can think of.
Here is the code that works with the hard-coded height.
<?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" >
<Spinner
android:id="#+id/fileType"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="300dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/ManageFiles_DeleteItem"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="5dip"
android:layout_weight="1"
android:text="Delete item" />
<Button
android:id="#+id/ManageFiles_DeleteAll"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="5dip"
android:layout_weight="1"
android:text="Delete all" />
<Button
android:id="#+id/ManageFiles_DisplayItem"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="5dip"
android:layout_weight="1"
android:text="Display item" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/ManageFiles_OKcustom"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="10dip"
android:layout_weight="1"
android:text="OK" />
<Button
android:id="#+id/ManageFiles_CancelCustom"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="10dip"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
`
You can try something as simple as
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/spinner1"
android:layout_above="#+id/button1" >
</ListView>
<Button
android:id="#id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button1" />
<Button
android:id="#id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Button2" />
The trick is to use RelativeLayout instead of LinearLayout.
Use the Following
android:weightSum="Your total length" //in your main layout
android:layout_weight="" //in each of your listview,spinner,linearlayout
Eg: if u need equal space for all 3 elements use
android:weightSum="3"
then in
Spinner
android:layout_weight="1"
/>
ListView
android:layout_weight="1"
/>
LinearLayout
android:layout_weight="1"
/>
Use weight, give weight of two to the list view and 1 each to the spinner and layout at bottom containing the buttons you can then vary the weight and check out which suits you more.
Try it like this way it will fit to all screen size.
<?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"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ftr_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/ManageFiles_DeleteItem"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="5dip"
android:layout_weight="1"
android:text="Delete item" />
<Button
android:id="#+id/ManageFiles_DeleteAll"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="5dip"
android:layout_weight="1"
android:text="Delete all" />
<Button
android:id="#+id/ManageFiles_DisplayItem"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="5dip"
android:layout_weight="1"
android:text="Display item" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/ManageFiles_OKcustom"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="10dip"
android:layout_weight="1"
android:text="OK" />
<Button
android:id="#+id/ManageFiles_CancelCustom"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_margin="10dip"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
<Spinner
android:id="#+id/fileType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/ftr_btn"
android:layout_alignParentLeft="true"
android:layout_below="#+id/fileType" >
</ListView>

CustomView in ListView

I am creating the listview using custom view(image + frameLayout) , but problem is that when i am clicking on the any item on the list view the getView method is called equal to number of items in the ilst view,
I am giving my xmi file here.
custon_layout.xml
<?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="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/ic_launcher"
/>
<FrameLayout
android:id="#+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Landed"
android:layout_gravity="center"
/>
<LinearLayout
android:id="#+id/ll1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="#+id/from_user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="hi"
android:textColor="#000000" />
<TextView
android:id="#+id/from_user_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="hi"
android:textColor="#000000" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
Please Help Me, Thanx in Advance.
hello i was changed your xml file of list please check this.
<?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="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/icon"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Landed"
android:layout_gravity="center"
/>
<TextView
android:id="#+id/from_user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="hi"
android:textColor="#000000" />
<TextView
android:id="#+id/from_user_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="hi"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
now for list item click clickhere
you can do same click for all list items and you can put different click for different view(mean list items).
its very simple if you have query then comment below.

Can we place two textviews in footer xml file in android?

I am displaying a header and footer for a listview. Here I am displaying all the data dynamically. Now I want to keep a title to my footer...So I tried to keep another textview in my footer.xml file. But it is not accepting. How can I place a title for my footer data?
My Code:
<?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:orientation="vertical" >
<TextView
android:id="#+id/exptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#000000"
android:textSize="12dip" >
</TextView>
</LinearLayout>
Help me regarding this...Thanks in Advance
Try this
using two layout one is using the textview and other is using the listview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:textColor="#ffffff"
android:layout_gravity="center_horizontal" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:textColor="#ffffff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
Another XML:
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
Do I get you right? You want to place a TextView above and one below a ListView?
Than you have to do it like this:
<?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:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="TextView" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="TextView" />
The Important part ist the layout_weight attributes.
Try this
you can us two xml one is set the two textview and other xml used the listview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:textColor="#ffffff"
android:layout_gravity="center_horizontal" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="welcome"
android:textColor="#ffffff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
Another XML:
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>

Bottom bar slides up with soft key board Android

My XML code is :
<?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">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="430dp"
android:fadingEdge="none"
android:layout_weight="1.0"
>
.......LinearLayout
</ScrollView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:background="#drawable/tabbarbottom"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/jobs"
android:text="About Us"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#drawable/white"
android:background="#android:color/transparent"
android:layout_centerVertical="true"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="12.5sp"
></Button>
<Button
android:id="#+id/aboutus"
android:text="Value"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#drawable/white"
android:layout_toRightOf="#id/jobs"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textStyle="bold"
android:textSize="12.5sp"
android:layout_weight="1"
></Button>
<Button
android:id="#+id/benefits"
android:text="History"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#drawable/white"
android:layout_toRightOf="#id/aboutus"
android:background="#android:color/transparent"
android:layout_centerVertical="true"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="12.5sp"
></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
The problem is that when ever user touches the edittext to type the bottom bar also rising up with keyboard.
How to resolve this?
Thanks
Please post your manifest file.I think in this activity you set :android:windowSoftInputMode="adjustResize" If after removing this line, problem is not fixed.Please contact with me.Yahoo+Skype:fsoft_duonghv.GoodLuck:)

Categories

Resources