I have an activity where i have a list view. On top of the list view i include another layout activity which contains two spinners for filtering the list view. But if i include the filters the list view is not working. It is not getting populated. If i remove it the list view is getting populated.
<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" >
<include android:id="#+id/filter" layout="#layout/activity_expense_list_filter" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="#id/filter"
android:layout_marginTop="23dp"
android:drawSelectorOnTop="false">
</ListView>
</RelativeLayout>
if i remove the filter view the list view is working as expected. Any ideas how i can resolve this
What is the layout for activity_expense_list_filter.xml? Does it also contain an element also called #android:id/list?
EDIT:
I have a feeling that, it being titled "filter", the included layout is completely obscuring your list. Is it's opacity at 100%?
I found the issue was because i have added width and height as match_parent in the other layout. so it is on top of the listview and it is occupying the entire width and height hiding the list view from the view. I set it to wrap_content and got it fixed.
Related
I have two ListView and I want them to share the same layout position so when I click a button one ListView hides.
Maybe this is not possible or there is a better way like fragments?
Use FrameLayout. This layout view overlies two views over each other.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
<ListView
android:id="#+id/list2"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</FrameLayout>
For showing the first page (i.e. the first ListView):
findViewById(R.id.list1).setVisibility(View.VISIBLE);
findViewById(R.id.list2).setVisibility(View.GONE);
And for the second page:
findViewById(R.id.list1).setVisibility(View.GONE);
findViewById(R.id.list2).setVisibility(View.VISIBLE);
fragments are the easy way to do this IF you don't plan on changing the data in your views.
Make a button and
/*create fragment of the opposite view, probably through a boolean field and an if block
then*/
getSupportFragmentManager.beginTransaction().replace(/*your fragments*/).commit().
in your onclicklistener.
So I have a TableLayout that I want to put inside a ScrollView. But I have a problem:
The TableLayout is initially empty and I programmatically add TableRows to it by tapping a button. This works fine if I put the TableLayout into the ScrollView normally.
But I want to put the TableLayout at the BOTTOM of the ScrollView. So every time I add a TableRow, the last cell will always be aligned to the bottom of the parent ScrollView. (kind of like how chat apps work - when you press send, your message is added at the bottom while all the other messages are pushed up).
What happens is that if I use android:layout_gravity="bottom" to try to achieve this, I'm unable to see any of the rows that are pushed upwards out of the view of the screen (I can't scroll upwards). However, I'm able to scroll downwards for some reason into emptiness, which shouldn't be possible since the last TableRow should be at the bottom.
Basically the problem is that I can scroll downwards where there are no TableRows but I can't scroll upwards where there are.
This is the relevant XML code:
<ScrollView
android:id="#+id/tableScrollView"
android:layout_width="match_parent"
android:layout_weight="0.7"
android:layout_height="0dip"
android:scrollbars="none"
android:orientation="vertical"
android:background="#drawable/stripes_background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">
<TableLayout
android:id="#+id/outputTable"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:divider="#drawable/table_divider"
android:showDividers="middle">
</TableLayout>
</RelativeLayout>
</ScrollView>
It looks like you should be using a ListView or some variant thereof; it provides support for all kinds of optimizations related to scrolling content. Take a look at some of the tutorials and developer docs available for custom ListView implementations.
EDIT Check out the question Listview Scroll to the end of the list after updating the list for details on performing the scroll operation you require using a ListView.
I have a list view in an Android application used to display an ArrayList containing Strings and I can't find any properties of the ListView that would allow me to align the text of the ListView Items to the right of it instead of the left. Any help would be great, thanks.
The answer depends on how exactly do you build the list. If you use the the standard ArrayAdapter then you could use the constructor:
ArrayAdapter<String>(Context, R.layout.aligned_right, values);
where R.layout.aligned_right is a xml layout like this:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="right"/>
This is because these parameters are not defined in the ListView, but in the ListAdapter instead. When you specify an adapter for the list, you should set it to return such a layout which aligns items on the right.
Add the below to the layout
android:layoutDirection="rtl"
This should suffice
android:layout_gravity="right"
For Expandable list view we create two row XMLs namely
One is group_row.xml and Other is child_row.xml.
make group_row.xml as
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/row_group_name"
android:layout_width="wrap_content"
android:textSize="24sp"
android:layout_alignParentRight="true"
android:textAllCaps="true"
android:layout_height="wrap_content" />
That is, a Text view aligned to parentRight inside a Relative Layout (which is match parent).
After 2 hours of struggling, I achieved this a moment ago.
image after
Pay attention to one small thing.
If you use listitem inside the listview, the gravity attribute of the listitem might not work if the listview layout:width is not set to match_parent.
My app requires the ability to add several views on one line in a user selected order.
I found this tutorial which seems to accomplish what I want with a bit of modification.
http://www.androidpeople.com/android-custom-listview-tutorial-example/
Having followed the tutorial and made the required changes, the code works except for one strange issue. The position increments but when it hits ~9 it returns to zero and then re-adds views that are already in the list and thus never reaches the >9 ones.
Also, if I scroll down to the bottom and then back up the very first entry has changed! It may change more but I haven't checked that.
Through some tests I have discovered that the textSize has some effect. If I set it small enough so that all 'rows' will show on screen at once then they appear fine.
This is my listview layout that gets inflated into the main 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="wrap_content"
android:minHeight="60dip"
style="#style/DefaultTheme">
<TextView
android:id="#+id/Line01"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#F00" />
<TextView
android:id="#+id/Line02"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#0F0" />
<TextView
android:id="#+id/Line03"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#00F"
android:layout_marginRight="5dip"/>
<LinearLayout
android:id="#+id/LinearLayout"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="2dip">
<TextView android:id="#+id/Name"
android:text="Name"
style="#style/Name" />
<TextView
android:id="#+id/Status"
android:text="Status"
style="#style/Status" />
</LinearLayout>
<ImageView
android:id="#+id/StatusImage"
style="#style/StatusImage" />
</LinearLayout>
I change background colours and text but that is all. Any ideas what is the problem?
Thanks!
That's because ListView recycles Views. It creates as many Views as required then the one which isn't available will be recycled as next.
So you have to set the colors/attributes in the getView or bindView methods of the adapter.
And btw. what you posted doesn't inflate the ListView, as there is no `' object in it. At best it could be a single ListView item, but not the listview itself ^^
I feel dumb for asking this now and not going back over the tutorial completely.
I was setting the values in my layout I place in the ListView on my main layout only when a new ViewHolder was created. Thus when I scrolled, the views were recycled, but never updated with the correct View settings.
All working fine now!
Cheers
I have a main menu screen with a simple ListView that contains "links" to further screens in my app (Browse, Bookmarks, Settings, About, etc.). Underneath the ListView there is a TextView (more accurately, a TextSwitcher that rotates TextViews) that changes every 10 seconds to display a new "tip".
In portrait mode, this works fine. There are my five list items in the ListView , and my tip label underneath. However, when I switch to landscape mode, the ListView is taller than the screen. The ListView scrolls normally, but I cannot scroll past the end of the ListView to see the TextView underneath.
I have tried every possible combination of Layouts, wrappers, ScrollViews, and layout_height parameters and I simply cannot get it to behave.
Here is the simplest code I can use to get the result pictured above:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/ListLayout"
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" android:layout_weight="1">
</ListView>
</LinearLayout>
<LinearLayout android:id="#+id/TipLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#+id/ListLayout">
<TextSwitcher android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TipSwitcher">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="7pt"
android:id="#+id/Tip1TextView" android:text="Tip: Hello, Android!"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tip: This is the second TextView in the TipSwitcher!"
android:id="#+id/Tip2TextView" android:textSize="7pt"></TextView>
</TextSwitcher>
</LinearLayout>
</RelativeLayout>
Like I've said, I've already tried so many different combinations that I can't list them, and for the most part I was randomly inserting XML in an attempt to get something to work the way I wanted. So I'd greatly appreciate suggestions as to how I would go about doing this the right way.
Thanks.
EDIT: Something I forgot to mention, this may or may not be relevant. My MainMenuActivity is extending ListActivity. According to the docs, "ListActivity has a default layout that consists of a single, full-screen list in the center of the screen." But, "If you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate()." So I don't think the ListActivity is interfering.
Put the TextSwitcher in the ListView itself. You can use addFooterView() for this.