Hi. Expert! I have a LinearLayout that have 4 buttons children. so I like to know whether my button is focusable or not when I press a arrow key. and I like to know whether my button is clicked or not when I click a child button. LinearLayout.onFocusChanged function is not called when child has focus. So I tried to find it. below code is my difficult and dirty solution. in below code, I should call button.setOnFocusChangeListener and button.setOnClickListener on every child button. If I have a hundred button, I should call button.setOnFocusChangeListener. and I don't need to know what button is exactly focuschanged. I just need to know whether my child buttons is focusChanged or not. and
what is a clear and simple solution? <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:id="@+id/layout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.windriver.Test.MyLayout android:id="@+id/layout2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:focusable="true"> </com.windriver.Test.MyLayout> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" android:focusable="true" /> </LinearLayout> public class MyLayout extends LinearLayout implements View.OnFocusChangeListener, View.OnClickListener { static final String TAG = "MyLayout"; public MyLayout (Context context) { this (context, null); } public MyLayout (Context context, AttributeSet attrs) { super (context, attrs); LayoutParams lp = new LayoutParams (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); Button button; for (int i = 0; i < 4; i++) { button = new Button (context); button.setText (String.format ("Button %d", i)); button.setOnFocusChangeListener (this); button.setOnClickListener (this); addView (button, lp); } } protected void onFocusChanged (boolean gainFocus, int direction, Rect prevRect) { Log.v (TAG, "onFocusChanged"); <----- this function is not called!!! why? } public void onFocusChange (View v, boolean hasFocus) { Log.v (TAG, "Button FocusChanged!"); } public void onClick (View v) { Log.v (TAG, "Button Clicked!"); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

