The main layout have four widgets- one EditText and three TextView as given below.
I want to add suggestion-list view dynamically as given below:
How to do it?
You can use AutoCompleteTextView. Described in http://developer.android.com/guide/topics/ui/controls/text.html.
Probably Custom adapter will help you to make two suggestions lists. Take a look at this Autocompletetextview with custom adapter and filter. I guess you need to create divider in custom adapter.
As described in comments. Just Make listview visible when you need to show suggestions. Or paste in eclipse and remove android:visibility="gone" attribute and you will see gray listview over textviews.
<?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:orientation="vertical" >
<EditText
android:id="#+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tv_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/search"
android:text="text1" />
<TextView
android:id="#+id/tv_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_1"
android:text="text2" />
<ListView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="#id/search"
android:background="#android:color/darker_gray"
android:visibility="gone" />
</RelativeLayout>
There is a class already built into android which gives you think functionality.
It's called AutoCompleteTextView
Related
I have created a grid layout Like this:
But I want my grid layout some thing like this:
I want my text to be appear on right side. Like Contacts List. Please tell me what changes I must have to do in my layout file. Waiting for a good response.
Since you seem to want a list and not a grid, you should use a LinearLayoutManager, not a GridLayoutManager.
See the official documentation for examples.
Try changing the orientation of your linerlayout to horizontal.
this the xml code just copy and past
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/android_list_view_tutorial_with_example"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/album"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:padding="5dp"
android:src="#drawable/pic1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YOUR TEXT"
android:id="#+id/album_title">
</TextView>
</LinearLayout>
In my app, there is a tabbed activity with three fragments. The first fragment has a form to create a new task, the second fragment has the list of all the saved tasks, and the third fragment will show the comments on a task when selected from the list in the second fragment. The third fragment is also supposed to act like a chat activity which posts comments when you type them in and tap the send button. The XML layout of this third fragment is as follows:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical"
tools:context="com.example.ishita.assigntasks.CommentsFragment">
<TextView
android:id="#+id/frag_task_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#dd55ff"
android:padding="10dp" />
<ListView
android:id="#+id/frag_comment_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:transcriptMode="normal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#android:color/white">
<EditText
android:id="#+id/frag_msg_edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:layout_weight="1" />
<ImageButton
android:id="#+id/frag_send_btn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/background_light"
android:contentDescription="#string/send_btn"
android:src="#android:drawable/ic_menu_send" />
</LinearLayout>
</LinearLayout>
As you can see, there is a TextView and a ListView and below that is another LinearLayout. Here is how it should look (the purple bar is the TextView):
And here is how it actually looks:
The TextView shows up above the ListView, but the LinearLayout does not. It is there, though. If I do android:layout_marginBottom="20dp" on the outermost LinearLayout, it does show up, but the ActionBar scrolls up and overlaps with the notification bar so that the title on the ActionBar and the notifications on the notification bar are both visible simultaneously and neither is legible.
I searched a lot and this seemed a common issue, but none of the solutions helped me. Believe me, I tried everything I could find. I tried wrapping the whole thing in a FrameLayout, using a RelativeLayout in place of the outermost LinearLayout, using two LinearLayouts--one to wrap the TextView and the ListView and the other to wrap the EditText and the ImageButton, etc., but nothing was able to show the bottom LinearLayout below the ListView. I even tried to set focus on the EditText when the fragment launches so that the keyboard would show and I can type, but even that doesn't help.
Note: On the other hand, if I use the exact same layout on an activity, the bottom LinearLayout displays exactly as it should.
I am unable to find the bug. Please help!
It looks like your toolbar pushes fragment layout down without decreasing its height. I have no idea why this happens (there are no root layout code here).
As a workaround you can set fragments layout bottom margin to ?attr/actionBarSize
As you have given layout_weight 1 in listview layout, so it occupies the whole space available. In order to get rid of you have to give some static height or use layout_weight in right manner
<ListView
android:id="#+id/frag_comment_list"
android:layout_width="match_parent"
android:layout_height="500dp"
android:transcriptMode="normal" />
or try like this
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical"
tools:context="com.example.ishita.assigntasks.CommentsFragment">
<TextView
android:id="#+id/frag_task_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#dd55ff"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:background="#android:color/white">
<ListView
android:id="#+id/frag_comment_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transcriptMode="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#android:color/white">
<EditText
android:id="#+id/frag_msg_edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:layout_weight="1" />
<ImageButton
android:id="#+id/frag_send_btn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/background_light"
android:contentDescription="#string/send_btn"
android:src="#android:drawable/ic_menu_send" />
</LinearLayout>
</LinearLayout>
All,
Thank you for all your responses. I found a workaround by trial and error now and thought I should post the answer for others who face the same issue. I set android:layout_marginBottom="50dp" on the inner LinearLayout (the one wrapping the comments bar--EditText and ImageButton). Somehow, this sets the layout correctly and the fragment functions properly in both Lollipop and Jellybean OS's. I haven't tested on other OS versions.
First of all you should read this, what is layout_weight and how it works.
You assigned layout_weight to ListView as 1, it means it covers whole height. just change it to 0.7 or any proportion you want (less than 1) will solve the problem.
<ListView
android:id="#+id/frag_comment_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:transcriptMode="normal" />
hello I'm trying to use Recyclerview,
below code results only a blank screen, can you please tell me where I'm going wrong
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top|center_vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/ImageSelectorRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal" />
<ImageView
android:id="#+id/ImageViewSelectPhoto"
android:layout_width="80dp"
android:layout_height="76dp"
android:src="#drawable/ic_add_a_photo_black_361px"
android:background="#drawable/back"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp" />
</LinearLayout>
Since you have provided
android:layout_width="match_parent"
android:layout_height="match_parent"
for your RecyclerView, its taking the full width and height of your device or parent view. And the ImageView is outside the device screen.
Now you have just declared the RecyclerView in your XML. You need a RecyclerView Row Layout which should define the layout for the RecyclerView items.
To show something in the RecyclerView you can set static data in the Row Layout layout iteself or need to create a RecyclerView adapter and model for dynamic/static data.
You need to make a list item layout for your Horizontal-scrollview and a seperate adapter also for it.
Try adding android:viewfillport="true"
I too asked a similar type of question ,please have a look to it yu will surely get a simple way to implement this .
Horizontal Listview Not Working from github
I think it should be similar to this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top|center_vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/ImageSelectorRecycler"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"/>
<ImageView
android:id="#+id/ImageViewSelectPhoto"
android:layout_width="80dp"
android:layout_height="76dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:src="#android:drawable/ic_dialog_alert"
android:background="#android:color/holo_green_dark" />
</LinearLayout>
I am programmatically creating view in Android. Parent layout is RelativLlayout and I'm adding two views in it. First is ListView and second is custom view. I want my second custom view to come on top of the list, but somehow it is getting hidden behind the ListView. How do I make sure that my custom view is on top.
Views get placed in the order you add them to their parent views. The view added last will be on top. You might also want to try
View.bringToFront() http://developer.android.com/reference/android/view/View.html#bringToFront()
Try to use: View.bringToFront();
Solution 1 - View#bringToFront()
View.bringToFront() should work if used properly. Maybe you forgot this (source: http://developer.android.com/reference/android/view/View.html#bringToFront()):
Prior to KITKAT this method should be followed by calls to requestLayout() and invalidate()
Solution 2 - reattach view
If View.bringToFront() will not work try to remove and add the view again. The advantage is that it has the same code on pre-KITKAT versions too.
I am doing it this way in my code:
ViewGroup parentView = (ViewGroup) (listView.getParent());
parentView.removeView(addFab);
parentView.addView(addFab);
Use FrameLayout, frame layout shows last added view on top..
Try this :
<?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" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<YourCustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
Please try adding android:elevation attribute to your view in the XML. It will always place your custom view over the ListView.
Again: Views get placed to the layout in the order you add it. Question is: is it realy hidden or does it not render?. Check LogCat and Console for errors. If you only add this single Custom View to your layout, does it get rendered without any problems? If so, ensure you realy add your custom to the same parent view (group), as you add your ListView. If you don't get any further, provide de respective code sample.
Give an elevation to the view which you want to bring up.
android:elevation="2dp"
This works for me :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="220dp"
android:gravity="bottom"
android:orientation="vertical"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="#+id/details_wrapper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingBottom="16dip"
android:scaleType="centerCrop"
android:src="#drawable/temp_nav_image">
</ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="Kapil Rajput"
android:textStyle="bold"
android:textColor="#android:color/black"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:textStyle="bold"
android:text="kapil#gnxtsystems.com"/>
</LinearLayout>
</RelativeLayout>
I used relative layout and the order of the views somehow determines which one is on top.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:splitTrack="false"
android:layout_alignParentTop="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
In this layout, the textview will be on top of the seekbar
Make parent view as relative layout and add your both view in xml.It wont work for Linear Layout.
And then add FirstView.bringToFront() programtically.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/bg"
android:orientation="vertical"
android:padding="15dp">
<ImageView
android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginBottom="-30dp"
android:layout_marginTop="30dp"
android:src="#mipmap/login_logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/imgIcon"
android:layout_gravity="bottom"
android:background="#B3FFFFFF"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<View 1/>
<View 2/>
</LinearLayout>
Java file
imgIcon.brigtToFront();
what you should do is using android:layout_below or android:layout_above programmatically. so you should do this:
RelativeLayout.LayoutParams params= new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, R.id.below_id);
viewToLayout.setLayoutParams(params);
and i suggest you take a look at this answer
hope this helps
I have made myself a custom LinearLayout by the name of com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget that hosts a couple of spinner widgets. This custom LinearLayout inflates the following XML layout (You might not need to look at this too carefully but it's here for completeness):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- Min value Spinner -->
<Spinner
android:id="#+id/discrete_numerical_range_selector_min_value_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_weight="1" />
<TextView
android:id="#+id/to_text"
android:text="to"
android:textSize="14sp"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_weight="0">
</TextView>
<!-- Max value Spinner -->
<Spinner
android:id="#+id/discrete_numerical_range_selector_max_value_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1" />
I have placed one such object in the layout for one of my activities like so:
<?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">
<include layout="#layout/search_form_section_generic_top"/>
<include layout="#layout/search_form_section_car_specific"/>
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget/>
<include layout="#layout/search_form_section_advanced_options" />
</LinearLayout>
The problem is that my app force closes immediately upon startup. I've checked by putting breakpoints in my custom LinearLayout that none of my custom code is even being run yet. Furthermore, if I copy-paste the layout code for my compound widget in place everything works, which indicates to me that I probably haven't left any important XML attributes out. What could be going wrong?
I fixed it by making the LinearLayout XML element in the widget layout into a merge instead, and moved all of the layout parameters out of the widget XML file and into the activity XML itself, thus replacing
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget/>
with
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
If someone could tell me why this worked, it might help me and others doing it again, and you can take credit.
because you must specify the width and height of every view you use in you xml?