I'm new to Android programming. I'd like to create an expandable list with a custom layout. The group contains image of my choosing, text view and another button of some sort serving as an update button for the group. The children layout has a text view and check box. When I attempted to add a image button to the group it disabled the drop down portion of the list so I switched that to a image view instead to get it working again. Basically I have most of it working except for a couple of things.
I'd still like to use a second image button to update the group. Also I'd like the check boxes when clicked to be able to update the image view or image button for the group. I added an onclicklistener for the check box within the expandablelist adapter's getchildview event but what happens is the 1st image for the list get's updated not the group that's expanded.
Group Layout:
<?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" >
<TextView
android:id="#+id/tvGroupName"
android:layout_width="434dp"
android:layout_height="40dip"
android:gravity="center_vertical"
android:paddingLeft="42dip"
android:textSize="20sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ivUpdateGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/update_description"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Children 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="40dip" >
<TextView
android:id="#+id/tvChildName"
android:layout_width="200dip"
android:layout_height="40dip"
android:gravity="center_vertical"
android:paddingLeft="50dip"
android:textStyle="bold" />
<CheckBox
android:id="#+id/cbCheckIn"
android:layout_width="60dip"
android:layout_height="40dip"
android:button="#drawable/check_image"
android:checked="false"
android:paddingTop="10dip" />
</LinearLayout>
Related
I am creating a chatting app in Android.
I was able to create the normal text chat list view with the following as the list item layout:
<?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="wrap_content" >
<TextView
android:id="#+id/chat_msg_view"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"/>
<TextView
android:id="#+id/msg_send_time"
android:layout_width="250dp"
android:layout_height="20dp"
android:layout_below="#+id/chat_msg_view"
android:layout_margin="2dp"
android:paddingTop="2dp"
android:textColor="#android:color/holo_blue_dark" />
<TextView
android:id="#+id/msg_status"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="#+id/msg_send_time"
android:layout_margin="2dp"
android:paddingTop="2dp"
android:textColor="#android:color/holo_blue_dark" />
</RelativeLayout>
But now i am trying to send images as well via chat. So now i need to replace the first TextView in the above layout to ImageView if content being sent is IMAGE.
What is a good approach to do this.
There are lots of approaches you can use. If you are using a list view adapter you can use itemType to change the entire list item layout (good if you are changing the entire layout, but can be a bit complicated) or you can place an image view at the same location in your layout as the text view and show or hide which ever one you are using. I.E. If showing image, show the image view and hide the text view, if you are showing the text view, show the text and hide the image. Then you don't need to insert/remove views at run time, which is a little more complicated.
Your layout might look a bit like 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="wrap_content" >
<TextView
android:id="#+id/chat_msg_view"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"/>
<ImageView
android:id="#+id/chat_image_view"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:visibility="gone"/>
<TextView
android:id="#+id/msg_send_time"
android:layout_width="250dp"
android:layout_height="20dp"
android:layout_below="#+id/chat_msg_view"
android:layout_margin="2dp"
android:paddingTop="2dp"
android:textColor="#android:color/holo_blue_dark" />
<TextView
android:id="#+id/msg_status"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="#+id/msg_send_time"
android:layout_margin="2dp"
android:paddingTop="2dp"
android:textColor="#android:color/holo_blue_dark" />
</RelativeLayout>
Notice how chat_image_view is also aligned to parent left.. it will be on top of the text view, but it has visibility "gone" so you wont see it.
Hope this helps, good luck.
I ran into a strange problem when dealing with AutoCompleteTextViews.
I've got the following layout for my items:
<?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:minHeight="48dp"
android:orientation="horizontal"
android:padding="8dp" >
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Some place I already visited"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton android:id="#+id/starred"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:background="#drawable/starred"
android:textOn=""
android:textOff=""/>
</LinearLayout>
Now my Adapter sets the Visiblity of the ToggleButton for some items to Gone and for other to Visible. The ítems where it's gone work as expected you can click them and the text gets put into the AutoCompleteTextView but where the ToggleButton is visible the items don't respond to touch. Altough you can interact with the ToggleButton.
Is there a way to make this work with AutoCompleteTextViews or do I have to use another type of View.
Simple make the ToggleButton from the row not focusable(with android:focusable="false" or in code, in the adapter, btn.setFocusable(false)).
i want to build an listview and each row has a checkbox with image and textview, i almost made it, but when i put the checkbox i can't press the list_row, i mean before i put the checkbox i can click the row and it hover as i did in my style, but after i put the checkbox when i click on the list_row it didn't hover and the onitemclick doesn't work, why ?
this is the xml of my each list_row
<?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="wrap_content"
android:background="#drawable/restaurant_list_item_selector"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:background="#drawable/restaurant_list_item_image_bg"
android:padding="3dip" >
<ImageView
android:id="#+id/restaurant_multi_select_list_item_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="#drawable/rihanna" />
</LinearLayout>
<TextView
android:id="#+id/restaurant_multi_select_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/thumbnail"
android:layout_toRightOf="#+id/thumbnail"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
<!-- Rightend check box -->
<CheckBox
android:id="#+id/restaurant_multi_select_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:checked="false"
/>
</RelativeLayout>
Adding focusable elements (like CheckBox or Button) disables the ability to click the overall list item and their focusability has to be disabled.
Add the following in your checkbox attributes in the xml and then try
android:focusable="false"
android:focusableInTouchMode="false"
Hope this helps!!!
yeah because checkbox presence makes the view unclickable.You need to implement onClicklistenrs of both ImageView and TextView you are using and write same code on thier click as you wanted on list row click
Setting focus will help only with touching but checkbox click will be implemented as well
I have a ListView that inflate for each row a xml that contain a CheckBox and more TextViews that are in a RelativeLayout.
The problem is that I can't figure out how to pass onClick events from checkbox to back row.
I want to achieve this behavior: The user press the checkbox and the whole list row gets pressed. I saw this behavior if I inflate for each row android.R.layout.simple_list_item_multiple_choice but I can't figure out how to do that without this android specific layout.
Can anybody give me an idea or direction?
Below is the code:
Listview :
<ListView
android:id="#+id/include_sent_list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:cacheColorHint="#color/white"
android:layout_alignParentTop="true"/>
And the xml that is inflated for each row:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox
android:id="#+id/checked_radio_button"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:focusable="false"
/>
<TextView
android:id="#+id/account_number_text"
android:layout_width="100dp"
android:layout_height="fill_parent"
style="#style/config_simple_small_text_view_style"
android:paddingTop="15dp"
android:layout_toRightOf="#id/checked_radio_button"
/>
<TextView
android:id="#+id/account_name_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="#style/config_simple_small_text_view_style"
android:paddingTop="15dp"
android:layout_toRightOf="#id/account_number_text"/>
</RelativeLayout>
The Checkbox consumes focus for the List item. You need to set this in your layout file:
<!-- Must make this non-focusable otherwise it consumes -->
<!-- events intended for the list item (i.e. long press) -->
<CheckBox
android:id="#+id/item_entry_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:focusable="false"
/>
I am having a problem with my layout screen. What I am trying to achieve is a listview with multiple rows, each row having one Image view and two EditText views. At the bottom of the very last row, there should be two buttons (Submit & Cancel)
I have managed to get the row working successfully, but when adding the buttons I keep getting errors. The data is being read in from a cursor, which I find complicates things further.
Is there a way I can use a row layout inside a contentView layout?
Here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:src="#drawable/gm" >
</ImageView>
<EditText
android:id="#+id/firstLine"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="email"
>
</EditText>
<EditText
android:id="#+id/secondLine"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignRight="#id/logo"
android:layout_alignParentRight="true"
android:layout_below="#id/firstLine"
android:text="password"
>
</EditText></RelativeLayout>
Create a separate layout with the bottom buttons and add it as a footer. You can also add a header btw.