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
Related
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 set one Gribview and one listview in an Activity,In the Gridview there is a TextView and a Button,What I want do is ,when I click the button ,can add a data to the listView .and the button and listView in different layout files.
the xml code is :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:descendantFocusability="blocksDescendants"
>
<ImageView
android:id="#+id/image"
android:layout_width="180dp"
android:layout_height="160dp"
android:layout_gravity="fill"
android:padding="4dp"
android:scaleType="fitXY" />
<LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:text="prices"
/>
<TextView
android:id="#+id/prices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:text="name"
/>
</LinearLayout>
<LinearLayout android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="9" />
<Button
android:id="#+id/add"
android:layout_width="45dip"
android:layout_height="45dip"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:text="+"
android:layout_weight="0.2"
android:textSize="12pt"
/>
</LinearLayout>
</LinearLayout>
I want to realize when I click the button ,the sequence number of the image I pick can add to the listView.
ADD:
maybe I didn't say it clear.I have gridView and listView in one layout file.In the gridView I define an layout file ,which contain an ImageView and a Button.What I realize is ,when the app run,I have obtain the button's action in getView,What I want:in button events ,how to write the position values in listView.I haven't got the solution yet ,it really bother me ,thankx for any help.
ADD2:
Now I have achieved the adapter.notifyDataSetChanged()adding data in ListView.but I don't know how to obtain the string variable in Acitivity,the string variable is given by text(TextView android:id="#+id/prices") in ListView to Activity.When I refresh View(adapter.notifyDataSetChanged()),I get "0". why?could anyone help?thank a lot.
You'll need to begin by adding a ListView to your layout file, and adding a button handler.
Take a look at Dynamically add elements to a listView Android
This links to a Stack Overflow question/answer that should get you started
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'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>
I have a layout with 3 button at the top in a row and then a ListView followed by a button below the listView.
This is my layout.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="#+id/btn_top10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOP 10"/>
<Button android:id="#+id/btn_top100"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOP 100"
android:layout_toRightOf="#id/btn_top10"/>
<Button android:id="#+id/btn_showAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show All"
android:layout_toRightOf="#id/btn_top100"/>
<ListView android:id="#+id/LV_Device"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/btn_top10"
android:layout_above="#id/LV_Device"/>
<Button android:id="#+id/btn_clearResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Clear Results"
android:layout_below="#id/LV_Device"/>
</RelativeLayout>
This will give a result like this
If i add some values to the ListView then its ok, the button below will be show
But if the listview becomes larger than the screen size then the button below that will not be visible even after scrolling to the bottom of the listView
How to solve this issue?? I don't want button to be fixed at the bottom of the screen. I want the button to be show at the end of the ListView only
Change your ListView's height to 0dip. Then change the attribute
android:layout_above="#id/LV_Device"
to
android:layout_above="#+id/btn_clearResult"
Finally, modify the last button by removing android:layout_below and add instead android:layout_alignParentBottom="true".
If you got the answer, this is for those who still come in search of the answer for your question. You should be using ListView.addFooterView(yourbutton) to your list.
(but don't forget to put this statement before setting adapter for your listview, as stated in the document.)
Shijilal
you maybe try this
your top button
your bottom group button
put your RelativeLayout in a scroll view this way your button will be displayed even after the scroll use this might work
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:paddingTop="10dip"
android:layout_height="fill_parent"
android:paddingBottom="10dip">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_top10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOP 10" />
<Button
android:id="#+id/btn_top100"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOP 100"
android:layout_toRightOf="#id/btn_top10" />
<Button
android:id="#+id/btn_showAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show All"
android:layout_toRightOf="#id/btn_top100" />
<ListView
android:id="#+id/LV_Device"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/btn_top10"
android:layout_above="#id/LV_Device" />
<Button
android:id="#+id/btn_clearResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Clear Results"
android:layout_below="#id/LV_Device" />
</RelativeLayout>
Initialy no item in the listView.so clear result button at the top. After add some item clear button goes down. But when more items are added clear button goes down & out of screen resolution. I want to know that Initialy when items are added clear button goes down. when clear button reached at bottom then it will not goes down further. you can add more items in the list view.