2014-06-26 2 views
0

У меня есть стандартная активность, которая имеет ListFragment «встроенный» в макет через XML. ListFragment определяется пользовательским адаптером.onListItemClick не работает в ListFragment, размещенном в действии

Хотя список заполняется, я не могу нажать на элементы списка; клик не регистрируется вообще. В макете списка есть только два TextView s.

Вот код для ListFragment код:

public class alarmList extends ListFragment { 

    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 

     String[] values = new String[] { "Android", "iPhone", "WindowsMobile", 
       "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", 
       "Linux", "OS/2" }; 

     // use your custom layout 
     alarmListCustomAdapter adapter = new alarmListCustomAdapter(getActivity(), values, "fonts/Lato-Light.ttf"); 
     setListAdapter(adapter); 

    } 

    @Override 
    public void onListItemClick(ListView l, View v, int position, long id) { 
     Log.i("checking: ", "WORKING"); 
     String item = (String) getListAdapter().getItem(position); 
     Toast.makeText(getActivity(), item + " selected", Toast.LENGTH_LONG).show(); 
    } 

} 

Вот расположение элемента списка:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:scrollbars="none" 
    android:background="#dfdfdf" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:focusable="false"> 

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:background="#fbfbfb" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginTop="5dp" 
      android:layout_marginLeft="6dp" 
      android:layout_marginRight="6dp" 
      android:paddingBottom="14dp" 
      android:paddingTop="14dp" 
      android:paddingLeft="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_horizontal_margin" > 

      <TextView 
       android:id="@+id/alarm_time" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="@string/wall_clock_hint" 
       android:textSize="25sp" 
       android:layout_alignParentLeft="true" 
       android:focusable="false" 
       android:focusableInTouchMode="false"/> 

      <TextView 
       android:id="@+id/alarm_label" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/alarm_time" 
       android:layout_marginTop="8dp" 
       android:textSize="15sp" 
       android:focusable="false" 
       android:focusableInTouchMode="false" 
       android:hint="LABEL"/> 

     </RelativeLayout> 

     <View 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_width="fill_parent" 
      android:layout_height="5dip" 
      android:background="@drawable/drop_shadow"> 
     </View> 

    </LinearLayout> 


</ScrollView> 

Что может быть не так?

Я прошел аналогичные вопросы по SO, но ни один из решений не работал для меня.

+0

Вы пробовали 'convertView.setOnClickListener()' на 'getView'' alarmListCustomAdapter'? –

+0

Нет. Не могли бы вы сообщить мне, как это сделать? –

+1

Не вставляйте прокручиваемые виджеты ('ScrollView') в другие прокручиваемые виджеты (' ListView'). – Luksprog

ответ

1

Не вставляйте прокручиваемые виджеты, такие как ScrollView (из макета строки) в другой прокручиваемый виджет, такой как ListView.

Смежные вопросы