0
我在主activity內有一個片段。片段包含一個圖像視圖。我的目標是將圖像視圖分成3個不同的按鈕。因此,我設置了一個線性佈局,它與圖像視圖,它包含3個可以在同等重力下點擊的視圖。Android OnClick不能在Android 4.3上工作
在我實現OnClickListener的片段,因爲這個 -
public class FragmentHomeMenu extends Fragment implements OnClickListener {
View view;
Context activity_context;
View button_search_1;
View button_search_2;
View button_search_3;
...plenty of other stuff
public FragmentHomeMenu() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home_menu, container, false);
activity_context = getActivity().getApplicationContext();
button_search_1 = (View) view
.findViewById(R.id.button_search_1);
button_search_1.setOnClickListener(this);
button_search_2 = (View) view.findViewById(R.id.button_search_2);
button_search_2.setOnClickListener(this);
button_search_3 = (View) view.findViewById(R.id.button_search_3);
button_search_3.setOnClickListener(this);
....plenty of other stuff
return view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
activity_context = activity.getApplicationContext();
}
@Override
public void onClick(View v) {
Log.w("", "some thing was clicked");
switch (v.getId()) {
case R.id.button_search_2:
dostuff1();//stuff1 is not happening in android 4.3,but works on 4.0
break;
case R.id.button_search_1:
dostuff2();//stuff2 is not happening in android 4.3,but works on 4.0
break;
......plenty of other stuff
}
我檢查了在很多地方的問題,但找不到solution.My代碼工作完美搭載Android 4.0 設備,但在4.3什麼當我點擊圖像時發生。
這裏是XML-
.......
<ImageView
android:id="@+id/imageview_searchbar"
android:layout_width="370dp"
android:layout_height="wrap_content"
android:layout_below="@+id/rltv1"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/search_bar" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageview_searchbar"
android:layout_alignLeft="@+id/imageview_searchbar"
android:layout_alignRight="@id/imageview_searchbar"
android:layout_alignTop="@+id/imageview_searchbar"
android:orientation="horizontal"
android:weightSum="21" >
<View
android:id="@+id/button_search_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="7"
android:clickable="true" />
<View
android:id="@+id/button_search_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:clickable="true" />
<View
android:id="@+id/button_search_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:clickable="true" />
</LinearLayout>
.......lots of other stuff
我最接近的猜測是,有一些問題,我通過上下文可能....是在Android 4.3不同的處理.....仍然我不知道確切的方式來傳遞它使用frekments – 2014-10-17 17:30:28
請嘗試使用屬性 - - android:descendantFocusable =「blockdescendants」 – 2014-10-17 17:40:48
我應該在哪裏使用屬性....我用它的線性佈局.....它沒有縫工作:/ – 2014-10-17 17:54:30