ListView Selector on Specific Element Within ListView View - android

I'm having a problem where I want each subchild of a view for a listview to have it's own custom selector. There are a few solutions already but none of them seem to work at all for me. Here's my xml for the listview and individual view. Does anyone know specifically what I need to do? Right now If I can get show_group_actions and action_calendar to have separate selectors working I'd be quite happy...
<?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="wrap_content"
android:descendantFocusability="afterDescendants"
android:orientation="vertical">
<LinearLayout
android:id="#+id/action_show_group_actions"
style="#style/AppTheme.NavigationDrawer.Row"
android:paddingRight="0dp"
>
<TextView
android:id="#+id/group_name"
style="#style/AppTheme.NavigationDrawer.Row.TextView"
android:text="#string/label_my_groups"
/>
<RelativeLayout
style="#style/AppTheme.NavigationDrawer.Group.OpenClose"
>
<me.magneto.groups.views.IconView
android:id="#+id/action_show_group_actions_arrow"
style="#style/AppTheme.NavigationDrawer.Group.OpenClose.Arrow"
android:text="#string/icon_chevron_down"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/action_calendar"
style="#style/AppTheme.NavigationDrawer.Group.Row"
>
<me.magneto.groups.views.IconView
style="#style/AppTheme.NavigationDrawer.Group.IconView"
android:text="#string/icon_calendar"
/>
<TextView
style="#style/AppTheme.NavigationDrawer.Row.TextView"
android:text="#string/label_calendar"/>
</LinearLayout>
</LinearLayout>
<ListView
android:id="#+id/navigation_drawer_list_view"
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:listSelector="#null"
android:background="#color/navigation_primary_background"
/>

Related

Android extendablelistveiw child element in foreground

I'm not sure that extendable list is the best solution for this but this is the only thing that came to my mind.
Here is my problem:
I want to create a list and when I click on an element one (or maybe there'll be multiple) element'll appear and push down the other elements that are below it. This is how the extendable list works, but here comes my problem I want that the child element are in front of the group elements and I have no idea how could I do it.
Here it is a picture maybe you can understand it better:
As Gavriel requested:
main:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.example.lalala.listview.MainActivity">
<ExpandableListView
android:id="#+id/extd_list"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
group:
<?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="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:background="#000000">
<TextView
android:id="#+id/left_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_widthPercent="75%"
android:textSize="17dp"
android:textColor="#f9f93d" />
<TextView
android:id="#+id/right_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_widthPercent="25%"
android:layout_toRightOf="#+id/left_text"
android:textSize="17dp"
android:textColor="#f9f93d" />
</android.support.percent.PercentRelativeLayout>
expanded child:
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >
<TextView
android:id="#+id/extended_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="20dp"
android:paddingBottom="20dp" />
</android.support.percent.PercentRelativeLayout>
What i did in a similar situation was to copy the ExpandableListView's layout xml into my project, and modify it according to my needs, and create MyExpandableListView extends ExpandableListView that uses my version of the layout and doesn't change anything else. I hope this helps.

Listview not scrolling

I have a listview that holds expandable cards. Each card is 2 frame views, one for the un-expanded view and one for the expanded view. In the expanded view I have another listview - that doesn't scroll. Can anyone tell me why? Here's some code:
First listview:
<LinearLayout
android:background="#null"
android:id="#+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/groups_listview"
android:layout_width="match_parent"
android:divider="#null"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
2nd listview (Expanded Card Content):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
xmlns:fontawesometext="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_expandablelistitem_card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/corners_white_transparent"
android:orientation="vertical" >
<ListView
android:id="#+id/friendsInGroupListview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:divider="#null" >
</ListView>
</LinearLayout>
Expandable card:
<?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="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:padding="16dp" >
<FrameLayout
android:id="#+id/activity_expandablelistitem_card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</FrameLayout>
<FrameLayout
android:id="#+id/activity_expandablelistitem_card_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp" >
</FrameLayout>
</LinearLayout>
I'd never use wrap_content in the layout_height nor layout_width, it causes performance issues, as you may read here. Also setting a static width/height is not a good idea as it may lead to layout issues in several devices.
Said that, I always define my ListViews like this:
<ListView
android:id="#+id/who_list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical">
</ListView>
Setting your layout_weight within a LinearLayout with just this view inside it, you make yourself sure that ListView will have a good layout rendering and it will enable scrolling when needed.

How to show other views after list view height set to fill_parent

To prevent multiple GetView calling I have set the height of ListView to fill_parent.
How to show other views than the ListView itself?
The following layout is inflated in a ViewPager:
<?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"
android:padding="15dp" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
where the included layout is:
<?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"
android:padding="20dp" >
<ScrollView
android:id="#+id/prontuariohome_scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none" >
.
.
.
.
</ScrollView>
</LinearLayout>
EDIT: This solution won't work for view higher than a button
I don't understand what you want to achieve, but if you NEED to have the height as fill_parent for some reason and can't be any other value, you can put the ListView with inside a LinearLayout with the height="0dp" and weight="1". So would be something 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"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
Try to use following code
android:layout_height="0dp"
android:layout_weight="1"
in ListView tag
With android:layout_height="0dip" the view will take the rest of the free place
You said this solution is wont work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" android:layout_above="#+id/bt"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bt" android:layout_alignParentBottom="true"/>
just add it a android:layout_above="#+id/bt" to listview.
I'm sorry for being not clear.
Here is the link of the (probably) main thread asked here in Sof about the issue I was talking about.
After some tries I'm happy to give you the solution of my problem.
Giving another layout above the ListView lets the LV cuts the space not filled by the ListView itself
<?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"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>

Changing view order in the program

My main.xml has ListView and ImageView. Now ListView is behind the ImageView. How can I make when the user touch the screen, the ImageView is put behind the ListView. How can I implement in the program? My main.xml is as follow.
<?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:orientation="vertical"
>
<LinearLayout android:id="#+id/tracker_container"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical"
/>
<ImageView
android:id="#+id/imageView1"
android:contentDescription="#string/display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/im1"
/>
</LinearLayout>
You can try bring the list view to the top by using
listView.bringToFront()

ScrollView Not Responding

I have the following XML and am not doing anything fancy with overriding scrolling behaviors:
<?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
android:id="#+id/myscrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_weight="1">
<ListView
android:id="#+id/mylistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
<TextView
android:id="#+id/my_empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/my_foo"
android:gravity="center"
android:visibility="gone"
/>
</LinearLayout>
However, while the embedded listview does respond to presses and long presses, it does not scroll. What am I doing wrong?
The trailing TextView is the listview's emptyview.
ScrollView does not play nicely with any other view that scrolls natively, i.e WebView, ListView, etc.
Try a Relative layout and see if this does what you need.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/mylistview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alingParentTop="true"
/>
<TextView
android:id="#+id/my_empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/my_foo"
android:gravity="center"
android:visibility="gone"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
In android it should not put ListView inside a ScrollView. It will not work.
Take the ListView out of the ScrollView. It causes problems, and is unnecessary (ListView handles scrolling on its own.)

Categories

Resources