i have done Search suggestions in android by using edittext and listview.
what i need exactly is in my activity there are so many buttons after the edittext, when i type letters in edit text it will show the corresponding search in list view but buttons will be appearing after that listview.
my xml file looks like this..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Editext for Search -->
<EditText android:id="#+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Search products.."
android:inputType="textVisiblePassword"/>
<!-- List View -->
<ListView
android:id="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="after Edit Text"/>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Second Button"/>
</LinearLayout>
i am getting output as
wat i need is my list of suggeations should not disturb any buttons in background after that searchable edit text,, any help will be appreciated
Change your layout to this:: move the buttons before listView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Editext for Search -->
<EditText android:id="#+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Search products.."
android:inputType="textVisiblePassword"/>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="after Edit Text"/>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Second Button"/>
<!-- List View -->
<ListView
android:id="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Related
I have a ListView which I am populating using adapter arrays. I would like to add a search bar there, but whenever I add a search bar it repeats it, so I ended up making 2 layout files: one for the search-bar and the other one for the item-list.
ListView in my Android:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="16dp">
<ImageView
android:id="#+id/icon"
android:layout_width="40dp"
android:layout_height="70dp"
android:background="#color/bckground"
android:src="#drawable/placeholder" /> <!-- ree image-->
<LinearLayout
android:id="#+id/textContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/icon"
android:orientation="vertical"
android:paddingTop="16dp">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
tools:text="name" />
<TextView
android:id="#+id/surname"
android:layout_width="match_parent"
tools:text="surname" />
</LinearLayout>
ListView layout print-screen:
Search-bar file layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/searchtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Search.." />
<Button
android:id="#+id/sumbit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search" />
</LinearLayout>
Search-bar layout print-screen:
I would like to have the search-bar and item list in one layout.
How can I combine these two layout files together?
Add your listview in layout file which contains search bar.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/searchtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Search.." />
<Button
android:id="#+id/sumbit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search" />
<!--Add your list view here-->
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
I would like to have the search-bar and item list in one layout. How can I combine these two layout files together?
You can't. These are conceptually two different layouts. One describes each item in the list, which is provided by the ListView adapter, and the other describes the top level view that contains the ListView and any other views that you want as part of that layout.
I've been trying to create an app that would allow a user to enter timetable information but i'm getting stuck at the design part, the first "Edit Text" container is getting stuck behind the title header of the app and i'm not sure why. I'd like to make it so it's forced below the header (and the other containers are force below the one above it, like a stack)
Image showing problem
There is another container above the "Day of Week", you can just see the bottom part of it sticking out below the header. Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<EditText
android:id="#+id/ModuleCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/module_code"
android:inputType="text"
android:gravity="fill"
android:layout_gravity="bottom"
android:layout_weight="0.14"
/>
<EditText
android:id="#+id/DayOfWeek"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/day_of_week"
android:inputType="text" />
<EditText
android:id="#+id/StartTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/start_time"
android:visibility="gone"
android:inputType="text" />
<EditText
android:id="#+id/Duration"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/duration"
android:visibility="gone"
android:inputType="text" />
<EditText
android:id="#+id/SessionType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/type_of_session"
android:visibility="gone"
android:inputType="text" />
<EditText
android:id="#+id/Room"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/room"
android:visibility="gone"
android:inputType="text" />
<ListView
android:id="#+id/myListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1.07" />
</LinearLayout>
I had the exact same problem, i just added a margin-top to the LinearLayout so it clears the header. for example:
note here i use a percentRelativeLayout, but this works with all layouts.
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:layout_marginTop="55dp"<--- this one!
android:padding="10dp">
it is because the action bar is added externally on top of the view
you could either remove the action bar and add it to your xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="#298859"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light">
or simply as add a margin top to your first item
<EditText
android:id="#+id/ModuleCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/module_code"
android:inputType="text"
android:layout_marginTop="30dp"/>
Since picture is worth a thousands words:
So I want my first LinearLayout to act something like a action bar, not being pushed up by keyboard. I tried android:isScrollContainer="false" and adding in manifest "adjustPan" or "adjustResize", but i don't get what i want.
Here is my XML:
<!-- layout 1 -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/caller_info"
android:layout_alignParentTop="true"
android:isScrollContainer="false"
android:layout_marginTop="#dimen/last_message_margin">
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_caller_name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="#dimen/side_margins"
android:layout_marginStart="#dimen/side_margins"/>
</LinearLayout>
<!-- layout 2 -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/dialog"
android:layout_below="#+id/caller_info"
android:layout_above="#+id/write_msg_layout">
</LinearLayout>
<!-- layout 3 with edit text -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/write_msg_layout">
<EditText
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="#dimen/side_margins"
android:layout_marginStart="#dimen/side_margins"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit_text"
android:hint="Write Msg"
android:textColorHint="#color/grey_as_clouds"
android:background="#color/white_as_stone"
android:imeOptions="actionSend"
android:singleLine="true" />
</LinearLayout>
Finally got it. You must surround your view with ScrollView and use adjustResize.
And delete android:isScrollContainer="false".
This is a layout I'm having problems with (this is for ListActivity):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
<Button
android:id="#+id/negative_button"
style="#style/Button"
android_alignParentBottom="true"
android:layout_below="#android:id/empty"
android:layout_weight="1" />
</RelativeLayout>
What happens right now is the list is below header TextView ("path") as it should be, the button is at the bottom also as it should be, but the ListView is not aligned between the header (textview) and footer (button). Instead, the button is simply slapped on top of listview. How can I fix that?
You need to define the footer and header before the list, try something like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<!-- to see the button, you must to declare its width/height here
and not (as I think you did) in the style.xml -->
<Button
android:id="#+id/negative_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Button"
android:layout_alignParentBottom="true" />
<!-- also layout_weight doesnot change anything in RelativeLayout -->
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path"
android:layout_above="#id/negative_button" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
</RelativeLayout>
The TextView "empty" should not be below the TextView "empty".
If the Button must be at the bottom of the screen you can use
android:layout_alignParentBottom="true"
For the Button
Otherwise you can use this layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<LinearLayout
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
</LinearLayout>
<Button
android:id="#+id/negative_button"
style="#style/Button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/container" />
</RelativeLayout>
Or ever add the Button as a footer of you Listview :
mListView.addFooterView(mButton);
http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
The only things that you used are the ListView, the first TextView as a "top bar" and the Button as a "bottom bar", right? If it is the case, why did you keep the empty TextView?
Try to remove it and try this 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" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<!-- work also with android:layout_height="0dip" -->
<Button
android:id="#+id/negative_button"
style="#style/Button"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Saw on these questions, it might be help you:
1. Layout for ListView at top and Buttons in Bottom?
2. Android Layout with ListView between a "top bar" and "bottom bar"
3. Add a button in bottom of listview when the listview is empty (using ListActivity)
Hope this will be helpful and you'll have the expected result.
In my Java android application I use a listview to display information loading from the SQLite DB And a page footer also there in this page.
The problem is When there are more items loaded to the listview and need to scroll, since footer appears in the bottom of the page, the footer covers the the last item in the listview.
Simply I want to stop overlapping listview items by the footer.
Can any one help me achieve this please. Thanks inadvance.
Edits
<RelativeLayout android:id="#+id/relativeLayout1" android:layout_height="wrap_content" android:layout_width="match_parent">
<ListView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/companylistView"
android:listSelector="#drawable/item_focus_bkg">
</ListView>
<LinearLayout android:id="#+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" android:layout_alignParentBottom="true" android:background="#android:color/darker_gray" >
<TextView android:text="Footer Text"
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000" >
</TextView>
</LinearLayout>
</RelativeLayout>
Based on your requirement(And as you haven't posted XML layout here that you have tried so far), i assume and can suggest the following:
give bottom margin to your listview: android:layout_marginBottom="60dip"
If you are using RelativeLayout then just give listview as android:layout_above="#+id/footer"
I suggest to you go with 2nd option.
Update:
Based on the XML you have posted, try this correct XML layout:
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/companylistView"
android:layout_above="#+id/textView1">
</ListView>
<TextView
android:text="Footer Text"
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_alignParentBottom="true">
</TextView>
</RelativeLayout>
You should use list footer like this:
View footerView = ((LayoutInflater)getApplicationContext().getSystemService(getApplicationContext().LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listview_footer, null, false);
list.addFooterView(footerView,null,false);
try this:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical" >
<ListView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/companylistView"
android:listSelector="#drawable/item_focus_bkg" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#android:color/darker_gray" >
<TextView
android:text="Footer Text"
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>