java - Weird behaviour of ListView -


when add item below "add item below" comment shown below, onitemlongclick , listitemclick cannot work. once i've removed items below "add item below", work. what's wrong?

        <?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:background="@color/caldroid_transparent"         android:orientation="vertical">          <linearlayout             android:id="@+id/event_layout"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margintop="@dimen/event_list_margin"             android:layout_marginbottom="@dimen/event_list_margin"             android:orientation="horizontal">              <relativelayout                 android:layout_width="80dp"                 android:layout_height="80dp"                 android:orientation="vertical"                 android:layout_marginleft="@dimen/standard_margin_size">                  <textview                     android:id="@+id/event_day"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text="20"                     android:gravity="center"                     android:layout_centerhorizontal="true"                     android:textcolor="@color/caldroid_black"                     android:textsize="45dp" />                  <textview                     android:id="@+id/event_month_year"                     android:layout_width="fill_parent"                     android:layout_height="wrap_content"                     android:text="jan 2015"                     android:textsize="12dp"                     android:gravity="center"                     android:layout_below="@id/event_day"                     android:textcolor="@color/caldroid_black" />              </relativelayout>              <relativelayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:orientation="vertical"                 android:paddingtop="@dimen/standard_padding_size"                 android:paddingbottom="@dimen/standard_padding_size"                 android:paddingleft="@dimen/feed_item_profile_info_padd"                 android:paddingright="@dimen/feed_item_profile_info_padd"                 android:layout_marginleft="@dimen/feed_item_profile_info_padd"                 android:layout_marginright="@dimen/feed_item_profile_info_padd"                 android:id="@+id/event_set_colour">                  <textview                     android:id="@+id/event_title"                     android:layout_width="fill_parent"                     android:layout_height="wrap_content"                     android:text="title"                     android:textstyle="bold"                     android:textcolor="@color/caldroid_black"                     android:textsize="@dimen/standard_text_size" />                  <textview                     android:id="@+id/event_location"                     android:layout_width="fill_parent"                     android:layout_height="wrap_content"                     android:text="local"                     android:layout_below="@id/event_title"                     android:textcolor="@color/caldroid_black"                     android:textsize="@dimen/feed_item_profile_name" />                  <textview                     android:id="@+id/event_start_end_time"                     android:layout_width="fill_parent"                     android:layout_height="wrap_content"                     android:layout_below="@id/event_location"                     android:text="28 may 2015, saturday"                     android:textcolor="@color/caldroid_black"                     android:textsize="@dimen/feed_item_profile_name" />             </relativelayout>           </linearlayout>  <!-- add item below -->             <button                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="hello"/>     </linearlayout> 

eventfragment.java

public class eventfragment extends listfragment {      //set database allow user retrieve data populate eventfragment.java     private appointmentcontroller appointmentdatabase;     //list appointments     private list<appointment> allappointment;     eventadapter adapter;     appointment selected_appointment;      @override     public void onactivitycreated(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         //get appointment         appointmentdatabase = new appointmentcontroller(getactivity());         appointmentdatabase.open();         allappointment = appointmentdatabase.getallappointment();         //initialise arrayadapter adapter view         adapter = new eventadapter(getactivity(), r.layout.row_event, allappointment);         setlistadapter(adapter);           getlistview().setonitemlongclicklistener(new adapterview.onitemlongclicklistener() {              @override             public boolean onitemlongclick(adapterview<?> arg0, view view, int position, long id) {                 // remove code simplicity      }      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_listfragment, container, false);          return rootview;     }      @override     public void onlistitemclick(listview l, view v, int position, long id) {         super.onlistitemclick(l, v, position, id);         // remove code simplicity     } 

if wants make onitemclick work add

android:descendantfocusability="blocksdescendants"

to parent layout it:-

<?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:background="@color/caldroid_transparent"         android:orientation="vertical" android:descendantfocusability="blocksdescendants">  </linearlayout> 

when blocksdescendants can not onclick event on button in row of listview. can event on either row or button in row.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -