I have a screen in my app which displays some categories for the users to select, in a GridView, as following:
When a user clicks on a category, a button appears for the user to continue, as following:
The problem is, that the green button that appeared does not respond to #OnClick (I am using ButterKnife for views).
Here is the Layout xml:
activity_select_categories.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="#+id/g"
android:layout_height="match_parent" android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/h"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="22dp"
android:layout_marginBottom="22dp"
android:textSize="23sp"
android:text="CATEGORIES" />
<GridView
android:id="#+id/gridView_selectCategoriesLayout_categories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone"
android:clickable="true"
android:id="#+id/button_selectCategoriesLayout_continue"
android:alpha="0.8">
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#22c064"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerInParent="true"
android:background="#22c064"
android:src="#drawable/checkmark"
/>
</RelativeLayout>
Here is the custom grid view element:
grid_tem.xml
<com.entu.artapp.utils.SquareRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/root"
android:gravity="center_horizontal">
<com.entu.artapp.utils.SquareImageView
android:id="#+id/gridItem_squareImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:visibility="invisible"
/>
<com.entu.artapp.utils.SquareImageView
android:id="#+id/gridItem_selectedColor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e85349"
android:visibility="invisible"
android:alpha="0.45"
android:scaleType="centerCrop"/>
<com.entu.artapp.utils.SquareImageView
android:id="#+id/gridItem_constantGrey"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:alpha="0.45"
android:scaleType="centerCrop"/>
<com.entu.artapp.utils.RectangularLinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/s"
android:orientation="vertical">
<ImageView
android:id="#+id/gridItem_selectedCheckMark"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/checkmark"
android:visibility="invisible"
/>
</com.entu.artapp.utils.RectangularLinearLayout>
<ProgressBar
android:id="#+id/gridItem_progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:visibility="visible"/>
<TextView
android:id="#+id/gridItem_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#ffffff"
android:textSize="15sp"
android:textAllCaps="true"
android:textStyle="bold"
android:visibility="invisible"/>
And here is how I set the OnClick for my button:
#OnClick(R.id.button_selectCategoriesLayout_continue)
public void setContinueButton () {
ParseUser.getCurrentUser().put("followedCategories", categoriesSelectedList);
ParseUser.getCurrentUser().put("followedCategoriesNames", categoriesNamesSelectedList);
ParseUser.getCurrentUser().saveInBackground();
}
Can anyone help me in solving why does the button not respond to OnClick?
ButterKnife.inject(this) has been called.
Extra: I have an alpha animation on the button. Although I am calling .setVisibility(VIEW.GONE), the button disappears, but the place where the button is/was cannot be clicked. I have read on similar topics on animations and VIEW.GONE conflicts that it might be a bug, and suggested using .clearAnimation(). But, if i call that, the alpha animation resets, and it messes up my UI.
Can anyone help me solve any of these problems?
Cheers!
EDIT #1: The code where i animated the button:
#InjectView(R.id.button_selectCategoriesLayout_continue)
RelativeLayout continueButton;
categoriesGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
[...]
if (categoriesNamesSelectedList.size() == 0) {
deselectedAnimation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
continueButton.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
continueButton.startAnimation(deselectedAnimation);
}
}
Your button inside the RelativeLayout steals the click event from the layout. You should delete the Button from the RelativeLayout (as you anyway don't use it) and set the background of the RelativeLayout instead of the button.
Related
I have this ListView with an Adapter that extends BaseAdapter. Inside the
public View getView(final int position, View view, ViewGroup parent) {...}
I attach a clickListener to view like this:
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final LinearLayout llMatchInfo = v.findViewById(R.id.matchInfo);
if (llMatchInfo == null) return;
llMatchInfo.setVisibility(llMatchInfo.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
}
});
Then I have this one user complaining that when he clicks an element llMatchInfo is visible for a split second and then disappears again.
This is the only place the matchInfo view has it's visibility changed.
Can anyone help me figure out why this is happening?
Thanks in advance
Here's the outer XML for each item in my ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingEnd="5dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="10dp"
android:layout_height="fill_parent"
android:id="#+id/live_indicator">
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/match_data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
...
</LinearLayout>
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/match_info"
android:id="#+id/matchInfo" />
</LinearLayout>
</LinearLayout>
And the inner XML for the actual matchInfo (the part I want to toggle visibility on):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:id="#+id/team_logos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
... />
<ImageView
... />
</LinearLayout>
<TextView
... />
<TextView
... />
<TextView
... />
<LinearLayout
android:id="#+id/tv_channels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
... />
<ImageView
... />
</LinearLayout>
</LinearLayout>
What I have done is on button click I have hidden the barcode scanner i.e used the ObjectAnimator for "Y" translation. At the same time, recyclerview which is below barcode scanner will also be translated in "Y" direction using ObjectAnimator. Animation works great only problem that when recylcerview is "Y" translated, then below it has some white space and I am not able to make it fill whole space available. Check below code which I have used.
//scannerLayout is barcode scanner and recycler view is list
int height1 = scannerLayout.getHeight();
ObjectAnimator objectAnimator = ofFloat(scannerLayout, "translationY", 0, -1 * (height1));
objectAnimator.setDuration(1000);
objectAnimator.start();
ObjectAnimator objectAnimator1 = ofFloat(recyclerView, "y", barcodeInputBoxHeight); //barcodeInputBoxHeight - is height of edittext which is shown between toolbar and recyalerview
objectAnimator1.setDuration(1000);
objectAnimator1.start();
objectAnimator1.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animator) {
}
#Override
public void onAnimationEnd(Animator animator) {
// here I am doing some other stuff
}
#Override
public void onAnimationCancel(Animator animator) {
}
#Override
public void onAnimationRepeat(Animator animator) {
}
});
I tried setting new layout params for recyclerview onAnimationEnd but it didn't work.
Check the below video for exact problem
Video
Below is layout xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_pos"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".modules.pos.POSActivity">
<FrameLayout
android:id="#+id/screenFrame"
android:layout_width="match_parent"
android:layout_height="200dp"
android:elevation="6dp">
<com.journeyapps.barcodescanner.DecoratedBarcodeView
android:id="#+id/barcode_scanner"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.journeyapps.barcodescanner.DecoratedBarcodeView>
<ImageButton
android:id="#+id/imageButtonFlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="15dp"
android:background="#drawable/button_border"
app:srcCompat="#drawable/ic_action_flash"/>
<ImageButton
android:id="#+id/imageButtonInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="5dp"
android:layout_marginTop="25dp"
android:background="#drawable/button_border"
android:visibility="gone"
app:srcCompat="#drawable/ic_action_input_barcode"/>
</FrameLayout>
<FrameLayout
android:id="#+id/rlInputBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#color/colorPrimary"
android:elevation="8dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="10dp"
android:visibility="visible">
<EditText
android:id="#+id/editTextSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:background="#drawable/round_corner"
android:ems="10"
android:hint="Search"
android:imeOptions="actionSearch"
android:inputType="number"
android:paddingBottom="5dp"
android:paddingEnd="30dp"
android:paddingLeft="10dp"
android:paddingRight="20dp"
android:paddingStart="10dp"
android:paddingTop="5dp"/>
<ImageView
android:id="#+id/imageViewCloseInputBox"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="end|center_vertical"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:src="#drawable/ic_action_close_input_box"/>
<ImageView
android:id="#+id/imageViewSwitchKeyboard"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="end|center_vertical"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/ic_action_keyboard"/>
</FrameLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/buttonCheckOut"
android:layout_below="#+id/screenFrame"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"/>
<Button
android:id="#+id/buttonCheckOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:elevation="6dp"
android:text="Checkout"
android:textColor="#ffffff"/>
i am using below xml for my ListView item 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="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="16dp">
<ImageView
android:id="#+id/contact_item_icon"
android:layout_width="50dp"
android:layout_height="50dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="16dp">
<TextView
android:id="#+id/contact_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Feel The Light" />
<TextView
android:id="#+id/contact_item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_user_audio_call_dark"
android:id="#+id/btn_audio_call"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_user_video_call_dark"
android:id="#+id/btn_video_call"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Invite"
android:background="#drawable/selector_button_green_oval"
android:textColor="#color/white"
android:id="#+id/btn_invite"/>
</RelativeLayout>
</LinearLayout>
i know in this xml some views are overlapping each other but in my custom array adapter i make visibility to gone for some of them based on certain condition, but what this xml do is to disable my ListView onItemClickListener but if i exclude this from xml then onItemClickListener works fine but i want to make onItemClickListener work without removing xml
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_user_audio_call_dark"
android:id="#+id/btn_audio_call"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_user_video_call_dark"
android:id="#+id/btn_video_call"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Invite"
android:background="#drawable/selector_button_green_oval"
android:textColor="#color/white"
android:id="#+id/btn_invite"/>
</RelativeLayout>
In your adapter getView(), set onClickListener to each button.
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Do something
}
}
If you want to handle click event for entire list item then you need to set onClickListener to root LinearLayout of your listViewItem XML:
ListViewItem XML: Give an id to LinearLayout
<?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:gravity="center_vertical"
android:orientation="horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="16dp"
android:id="#+id/container">
<ImageView
android:id="#+id/contact_item_icon"
android:layout_width="50dp"
android:layout_height="50dp"/>
.................
...................
Adapter: Set OnClickListener to LinearLayout
#Override
public View getView(int position, View convertView, ViewGroup parent) {
.............
.................
LinearLayout container = (LinearLayout) convertView.findViewById(R.id.container);
container.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Do something
}
}
.................
...................
}
Hope this will help!
I am inflating a layout inside a dialog, which consist of a scrollview but the layout is not scrolling. I have referred so many questions from stackoverflow but then also its not working. My layout.xml is given below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#color/White"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:text="Update available"
android:textColor="#000000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="#string/upgrade_msg"
android:textColor="#000000" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_margin="3dp"
android:layout_weight="0.02"
android:src="#drawable/updateimg2" />
<Button
android:id="#+id/btn_upgrade"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_forget_pwd"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#color/White"
android:gravity="center"
android:text="Upgrade Now"
android:textColor="#color/Black" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="#drawable/line_y_h" />
<Button
android:id="#+id/btn_remind"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_forget_pwd"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#color/White"
android:gravity="center"
android:text="Remind Me Later"
android:textColor="#color/Blue" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:src="#drawable/line_y_h" />
</LinearLayout>
</ScrollView>
Dialog code
public void show_Alert_version_custom(String str, final String url,
final String exitStatus)// use for
{
final Dialog dialog = new Dialog(Splash.this);
dialog.setContentView(R.layout.version_update);
dialog.setTitle(getString(R.string.alert_title));
Button dialogButton2 = (Button) dialog.findViewById(R.id.btn_remind);
dialogButton = (Button) dialog.findViewById(R.id.btn_upgrade);
ImageView viewLine = (ImageView) dialog.findViewById(R.id.imageView2);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {}
});
// if button is clicked, close the custom dialog
dialogButton2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {}
});
dialog.show();
}
android:fillViewport="true" in ScrollView solved my problem. Now its scrolling even inside dialog.
You can use simply below code on ScollView. it's working fine.
<ScrollView>
<LinearLayout android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
</LinearLayout>
</ScrollView>
I have a list view and want to perform clickable event on it. I did it before. but now its not working. I have added my XML as well. I just need to move from one actvity to other on click in list view.
CustomFinalSubmit_ItemDetail item = new CustomFinalSubmit_ItemDetail(Final_Submit.this , R.layout.customview_finalsubmit_itemdetails, itemInfo);
itemList.setAdapter(item);
itemList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
FinalSubmitItem pos = itemInfo.get(position);
String itemType = pos.getItemType();
String itemCountry = pos.getItemCountry();
String itemSerial = pos.getItemNo();
pos.setChecked(true);
Intent inn = new Intent(getApplicationContext(), FinalSubmitDetails.class);
inn.putExtra("itemType", itemType);
inn.putExtra("itemCountry", itemCountry);
inn.putExtra("itemSerial", itemSerial);
startActivity(inn);
}
});
Here is my main Xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/green">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:layout_marginTop="10dip"
android:orientation="vertical"
android:background="#0B3B0B">
<ListView
android:id="#+id/CustomerDetailList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/yellow"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:id="#+id/Itemtype"
android:paddingTop="5dp"
android:background="#color/green"
android:textColor="#color/yellow"
android:layout_marginLeft="5dip"
android:text="Item Type"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingTop="5dp"
android:id="#+id/txtcountry"
android:background="#color/green"
android:textColor="#color/yellow"
android:text="Country"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingTop="5dp"
android:id="#+id/txtItemNumber"
android:background="#color/green"
android:textColor="#color/yellow"
android:text="Item No."/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:id="#+id/itemChck"
android:button="#drawable/custom_checkbox"
android:paddingTop="5dp"
android:padding="5dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_margin="5dp"
android:layout_height="1dp"
android:background="#color/white"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/itemList"
android:background="#088A08"
android:divider="#color/white"
android:dividerHeight="1dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I did it this way:
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
your code
}});
Just add this much code to my customview
Recently I had the same problem after adding a ToggleButton to my list items. The solution for me was to add android:descendantFocusability="blocksDescendants" to the layout of the item.
Here is the whole XML:
<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="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:paddingLeft="15dp"
android:descendantFocusability="blocksDescendants" >
<TextView
android:id="#+id/watch_roadName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Addresse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ToggleButton
android:id="#+id/watch_button_arrived"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/watch_roadName"
android:layout_alignParentRight="true"
android:textOn="#string/arrived"
android:textOff="#string/arrived"
android:text="#string/arrived" />
</RelativeLayout>
Similar answers to the same issue can be found here:
How to fire onListItemClick in Listactivity with buttons in list?
and here
Android custom ListView with ImageButton is not getting focus
in the widgets(Textview or button whatever it is) of your inflator layout just add:
android:focusable="false"
android:focusableInTouchMode="false"
and in parent layout of your inflator add:
android:descendantFocusability="blocksDescendants"