[英]TextView not passing control to its ListItem (Expandable list -> Group View)
我正在按照布局使用getGroupView()方法下的可擴展列表。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/groupheaderbg" android:layout_marginLeft="30dp">
<ImageView
android:id="@+id/groupimgview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="@string/groupImageViewDesc"
android:padding="@dimen/TENDP"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/lblheader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/childgroupimgview"
android:singleLine="true"
android:text="@string/groupImageViewDesc"
android:textIsSelectable="true"
android:textSize="18sp"
android:textStyle="bold"
android:gravity="center_vertical"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
/>
</RelativeLayout>
由於textview無法將可擴展列表擴展和折疊,因為textview沒有將click事件傳遞給可擴展列表項。 我嘗試了以下方法,所以現在沒有出現textview選擇菜單,但問題仍然相同(未將控件傳遞給列表項)。
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
/>
除此之外,我還嘗試遵循槽式代碼。
tv.setOnClickListener(null);
tv.setFocusable(false);
tv.setAutoLinkMask(Linkify.ALL);
tv.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// return TRUE since we want to consume the event
return false;
}
});
我需要攔截觸摸事件嗎? 如果是的話,請告知/建議相同。
或者有什么方法可以指示textview將touch事件/ click事件移交給它的父視圖。
感謝您的寶貴時間。
我將onclickListener應用於textview並以編程方式控制從此處展開和折疊。
如果有人發現更好的方法,請分享。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.