【发布时间】:2014-02-05 11:41:15
【问题描述】:
我有这个布局,但按钮不可点击。
我尝试了以前帖子中的解决方案,例如将android:focusable="false" 添加到按钮或列表视图或线性布局,但它不起作用。我尝试在按钮OnClickListener 之后添加:button.setFocusable(false),但也没有用。我什至尝试在主线性布局中添加:android:descendantFocusability="blocksDescendants",但问题仍然存在。
谢谢。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
<EditText
android:id="@+id/search_field"
android:layout_width="181dp"
android:layout_height="wrap_content"
android:layout_weight="1.25"
android:ems="10"
android:hint="Search"
android:textColor="#1F6260" />
<Button
android:id="@+id/refresh_button"
android:layout_width="34dp"
android:layout_height="32dp"
android:background="@drawable/refresh3" />
</LinearLayout>
<ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector">
</ListView>
</LinearLayout>
Java 代码:
refresh= (Button)myFragmentView.findViewById(R.id.refresh_button);
refresh.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
((MainTabs)getActivity()).refresh();
((MainTabs)getActivity()).getUsersList();
}
});
在 onclick 方法中添加了 toast 并且它显示了,所以我的代码不起作用并且按钮没有任何问题。很抱歉给您带来不便。 谢谢。
【问题讨论】:
-
你忘记关闭第一个
LinearLayout标签了吗? -
我只是忘了在这篇文章中添加它。
-
“不可点击”是什么意思?
-
@Krishna 它不响应点击。
-
你能在 onclick 方法里面放一个 toast
标签: android android-layout android-listview android-button