TextView not clickable in Spinner when spinner contains ImageButton - android

I am using below layout xml as spinner row element (custom spinner). I see items (textView and ImageButton) getting displayed in spinner, but the item is not clickable (disabled), though i can click on ImageButton. I would like to have item especially text to be shown in the spinner when text is selected.
I am using android api 28.
Please suggest on how to do this.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton
android:id="#+id/buttonIcon"
android:scaleType="centerCrop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_remove"/>
</LinearLayout>

Related

AutoCompleteTextView Items not Clickable when containing ToggleButton

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)).

Android layout : Align a TextView and a Spinner

I would like to align a textview (saying : "Day :") with a Spinner where the user can choose the day of the week he wants (Monday, Tuesday, etc.)
when I try to align them :
<TextView android:id="#+id/labelSpinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/textSpinner1"
android:layout_toRightOf="#+id/spinner_days"
android:layout_alignParentTop="true"/>
<Spinner android:id="#+id/spinner_days"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/labelSpinner1"
android:layout_alignParentLeft="true"
android:drawSelectorOnTop="true"/>
the result I get is that I only see the Spinner, and the TextView isn't showing (or is underneath the Spinner)
Thank you for your help!
I guess you want the Spinner to the right of the TextView? Check the following code:
<TextView
android:id="#+id/labelSpinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="#string/textSpinner1" />
<Spinner
android:id="#+id/spinner_days"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/labelSpinner1"
android:layout_toRightOf="#id/labelSpinner1"
android:drawSelectorOnTop="true" />
Your problem was that the spinner filled the whole view (android:layout_width="fill_parent") while you forced the TextView to be right of the Spinner (so outside of the screen --> invisible for you)

ListView Custom row not clickable entirely

I am creating an App, in which I am showing information from a database in a ListView, using a custom row layout, which is populated using a SimpleCursorAdapter. I also handle onItemClickListner for the ListView.
My Layout of the custom rows is as follows:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true"
android:padding="10dip" >
<ImageView android:id="#+id/imageButtonAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:src="#drawable/icon_account" />
<TextView
android:id="#+id/TextViewAccount"
style="#style/textView_normal_bold_style"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dip"
android:focusable="false"
android:focusableInTouchMode="false"
android:textSize="#dimen/text_size_large" />
</LinearLayout>
But I have one issue, which follows:
When I click above content of ListView row, it performs only click event, but what I want is when I click any where in a row then a click action should be performed. But it does not behave like this.
The XML of your row should have the attribute
android:layout_width="fill_parent"

Android custom spinner

I have a custom spinner that uses two custom views, one for the drop down and one for the currently selected item.
My problem is, the custom view for the currently selected item is always at least as wide as the longest item in the spinner list and it leaves a sizeable gap on the left hand side of my custom view. If I select the longest item from the spinner, the gap disappears. I have tried android:gravity="left" for my custom view. Also note that this only seems to be an issue with Android 3.0+.
Here is the code for my custom spinner view:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/folder_detail" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="wrap_content">
<TextView android:text="Folder Name"
android:id="#+id/folder_name" android:textColor="#ffffff"
android:layout_width="wrap_content" android:textSize="16sp"
android:textStyle="bold"
android:layout_height="wrap_content" android:layout_marginTop="0dp">
</TextView>
<TextView android:id="#+id/folder_count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="13sp" android:text="(0) " android:textColor="#color/light_blue" android:layout_marginLeft="2dp"/>
<ImageView android:id="#+id/icon" android:src="#android:drawable/arrow_down_float"
android:layout_marginRight="1dp" android:scaleType="fitXY"
android:layout_gravity="bottom" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
This is intentional. It prevents the spinner from drastically changing size as the selection changes.
You're not meant to include an arrow as part of the item view; this is normally included as part of the background 9-patch of the spinner itself. The gravity setting on the spinner itself controls the alignment of the selected item view within the spinner. The Holo theme aligns it to the left, while the legacy themes horizontally center.

Listview with checkbox issue

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"
/>

Categories

Resources