我有一個奇怪的問題,在我相當複雜的視圖佈局。 (我會盡量簡化它在我的解釋中)點擊事件ImageButton沒有立即調度
基本上我有一個ListView
,其中每個項目包括一個TextView
和ImageButton
。我能夠單擊列表項(在textview上)或按鈕(我將ImageButton設置爲不可聚焦,否則它將不起作用)
現在它似乎工作正常,直到我打開另一個窗口並返回到列表視圖。 從那時起,我可以單擊ImageButton而不發生任何事情(甚至在點擊過程中不會發生背景變化)。但是當我再次點擊TextView時,所有來自ImageButton的點擊事件都會立即分派。
這是爲什麼?
編輯:
列表項:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0px"
android:minHeight="40dp"
android:orientation="horizontal"
android:paddingLeft="2px"
android:paddingRight="2px"
>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Text"
android:textSize="19dp"
android:paddingTop="4px"
android:paddingBottom="4px"
android:layout_gravity="center_vertical"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/open_subtree_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="0px"
android:orientation="horizontal"
android:padding="0px">
<View
android:layout_width="1px"
android:layout_height="match_parent"
android:background="@drawable/separator_line" />
<com.treeviewer.leveldisplay.DontPressWithParentImageButton
android:id="@+id/btn_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/list_selector_background"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="10dp"
android:src="@drawable/arrow_right" />
</LinearLayout>
</LinearLayout>
這就是它是如何膨脹:
[...]
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = inflater.inflate(R.layout.tree_row, null, false);
TextView textView = (TextView)mView.findViewById(R.id.text1);
LinearLayout nextNodeButtonContainer = (LinearLayout)mView.findViewById(R.id.open_subtree_layout);
if(childCount >= 0) {
titleBuilder.append(" (" + childCount + ")");
nextNodeButtonContainer.setVisibility(View.VISIBLE);
View button = nextNodeButtonContainer.findViewById(R.id.btn_right);
button.setFocusable(false);
button.setFocusableInTouchMode(false);
//button.setClickable(true);
button.setOnClickListener(clickListener);
button.setTag(tagValue);
} else {
nextNodeButtonContainer.setVisibility(View.GONE);
}
textView.setText(titleBuilder);
讓我知道,如果你需要更多的代碼。
通過在這裏發佈一些代碼來幫助我們... – Optimus