ListView不可点击或LongClickable

时间:2014-08-19 07:40:49

标签: android android-listview

我有自定义listview但无法管理ClickLongClick 这是XML的{​​{1}}:

ListActivity

这是<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:descendantFocusability="blocksDescendants" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@id/activity_main_l2" android:layout_marginTop="44dp" android:layout_gravity="bottom" android:gravity="bottom"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/main" android:layout_gravity="center" android:gravity="bottom" android:visibility="visible" android:id="@id/activity_main_search_layer"> <EditText android:id="@id/activity_main_search_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:background="@drawable/message_field" android:hint="@string/Search_hint" android:textColor="@color/textFieldColor" android:layout_gravity="center" android:maxLines="8" android:paddingLeft="10dp" android:paddingTop="5dp" android:paddingRight="10dp" android:paddingBottom="10dp" android:textSize="14dp" android:singleLine="true"/> </LinearLayout> <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:divider="#00000000" android:background="#ffffff" android:fastScrollAlwaysVisible="true" android:fastScrollEnabled="true" android:listSelector="#00000000" android:focusable="true" android:focusableInTouchMode="true" android:clickable="true" android:longClickable="true"/> </LinearLayout> <include layout="@layout/header1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/include"/> <include layout="@layout/draver_menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/include1"/> </FrameLayout> 的{​​{1}}:

XML

ListRow

<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="70dp"
android:background="#fafafa"
android:gravity="end"
android:orientation="horizontal"
android:id="@id/list_row_rl"
android:padding="5dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants" >

<LinearLayout
        android:orientation="vertical"
        android:layout_width="70dp"
        android:layout_height="fill_parent" 
        android:layout_weight="0" 
        android:focusable="false" 
        android:focusableInTouchMode="false">
    <FrameLayout
            android:layout_width="70dp"
            android:layout_height="fill_parent"
            android:foregroundGravity="center"
            android:layout_gravity="center" 
            android:focusable="false" 
            android:focusableInTouchMode="false">
        <FrameLayout
            android:id="@+id/thumbnail"
            android:layout_width="60dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dip"
            android:padding="3dp" android:layout_gravity="center"
            android:foregroundGravity="center" 
            android:focusable="false" 
            android:focusableInTouchMode="false">

            <QuickContactBadge
                android:id="@+id/quickContactBadge1"
                android:layout_width="52dp"
                android:layout_height="52dp"
                android:scaleType="fitCenter"
                android:layout_gravity="center"/>
            <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="52dp"
                    android:layout_height="52dp"
                    android:background="@drawable/round_frame" 
                    android:layout_gravity="center"
                    android:gravity="center" 
                    android:focusable="false" 
                    android:focusableInTouchMode="false">
            </LinearLayout>
        </FrameLayout>
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:background="@drawable/rounded_counter" 
                android:layout_gravity="bottom|left"
                android:layout_marginLeft="4dp" 
                android:layout_marginBottom="10dp"
                android:id="@id/list_row_number_of_new_sms_layer"
                android:visibility="invisible" 
                android:focusable="false" 
                android:focusableInTouchMode="false">
            <TextView
                android:id="@+id/Numberofsms"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:text="420"
                android:textColor="#FFFFFF"
                android:textSize="10dp"
                android:textIsSelectable="false"
                android:singleLine="true"
                android:gravity="center"
                android:layout_gravity="center"
                android:textColorHighlight="#000000"
                android:autoText="false"
                android:layout_marginLeft="4dp"
                android:layout_marginTop="3dp"
                android:layout_marginRight="5dp" 
                android:focusable="false"
                android:focusableInTouchMode="false"/>
        </LinearLayout>
    </FrameLayout>
</LinearLayout>
<FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@id/list_row_click_button"
            android:background="#fafafa"
            android:focusable="false" 
            android:focusableInTouchMode="false"/>
    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:id="@id/list_row_click_layer">
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent" 
                android:layout_weight="1" 
                android:focusable="false" 
                android:focusableInTouchMode="false">
            <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="68dp"
                     android:id="@id/list_row_l1"
                    android:gravity="right|top" 
                    android:layout_gravity="left|top" 
                    android:focusable="false"
                    android:focusableInTouchMode="false">
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:layout_gravity="center|left|top"
                    android:layout_marginRight="5dp" 
                    android:gravity="left|top"
                    android:focusable="false"
                    android:focusableInTouchMode="false">

                    <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="fill_parent"
                            android:layout_height="35dp" 
                            android:layout_gravity="left|top"
                            android:gravity="left|top"
                            android:focusable="false"
                            android:focusableInTouchMode="false">
                        <TextView
                                android:id="@+id/ContactName"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:layout_weight="0.60"
                            android:text="@string/ContactName"
                            android:textColor="#666666"
                            android:textSize="16dp"
                            android:textStyle="bold"
                            android:typeface="sans"
                            android:textAlignment="gravity"
                            android:layout_gravity="left|top"
                            android:layout_marginRight="5dp"
                            android:gravity="left|top"
                            android:phoneNumber="true"
                            android:layout_marginLeft="5dp" 
                            android:maxHeight="40dp"
                            android:singleLine="true"
                            android:focusable="false" 
                            android:focusableInTouchMode="false" />
                        <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="fill_parent"
                                android:id="@id/list_row_count" 
                                android:singleLine="true"
                                android:layout_marginLeft="5dp" 
                                android:layout_marginRight="5dp"
                                android:layout_gravity="left|top" 
                                android:gravity="left|top"
                                android:textSize="16dp" 
                                android:focusable="false" 
                                android:focusableInTouchMode="false"/>
                    </LinearLayout>
                    <TextView
                        android:id="@+id/LastSMS"
                        android:layout_width="fill_parent"
                        android:layout_height="20dp"
                        android:text="سلام امروز روز خوبی است."
                        android:textColor="#aeaeae"
                        android:textSize="12dp"
                        android:singleLine="true"
                        android:layout_marginRight="5dp"
                        android:phoneNumber="false"
                        android:layout_marginLeft="5dp"
                        android:layout_marginBottom="2dp"
                        android:linksClickable="true"
                        android:autoLink="web"
                        android:layout_gravity="center_vertical|left" 
                        android:gravity="center|left" 
                        android:focusable="false" 
                        android:focusableInTouchMode="false"
                            />
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="2dp" 
                    android:background="#f34323" 
                    android:focusable="false" 
                    android:focusableInTouchMode="false">
            </LinearLayout>
        </LinearLayout>
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="70dp"
                android:layout_height="fill_parent"
                android:layout_weight="0"
                android:layout_gravity="top" 
                android:gravity="top" 
                android:focusable="false"
                android:focusableInTouchMode="false">
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="68dp"
                    android:foregroundGravity="left|top"
                    android:orientation="vertical"
                    android:layout_gravity="center|top"
                    android:gravity="center|top" 
                    android:focusable="false" 
                    android:focusableInTouchMode="false">
                <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/list_row_draft_text"
                        android:id="@+id/list_row_draft_textview"
                        android:layout_gravity="right"
                        android:textSize="8dp" 
                        android:textColor="#ff00ac"
                        android:visibility="invisible"
                        android:focusable="false" 
                        android:focusableInTouchMode="false"/>
                <TextView
                    android:id="@+id/Date"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="5:45"
                    android:textColor="#aeaeae"
                    android:textSize="11dp"
                    android:gravity="center_vertical"
                    android:layout_gravity="right" 
                    android:layout_marginBottom="10dp"
                    android:focusable="false" 
                    android:focusableInTouchMode="false"/>
            </LinearLayout>
            <LinearLayout android:orientation="vertical" 
                          android:layout_width="fill_parent"
                          android:layout_height="2dp"
                          android:background="#f34323"
                          android:id="@+id/linearLayout" 
                          android:focusable="false" 
                          android:focusableInTouchMode="false"/>
        </LinearLayout>
    </LinearLayout>
</FrameLayout>

</LinearLayout>

但不是这些听众获得ListActivity list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { some code... } }); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> a, View v, int position, long id) { some code... } });
Click(android:id =“@ + id / ContactName”)之一的LongClick工作

LongClock

TextView

任何建议?

0 个答案:

没有答案