I have multiple buttons in an Activity. Each button opens a separate AlertDialog. When the app starts and i CLICK on a button through mouse, i want the clicked button to get focus .. so i can navigate through D-Pad buttons too afterwards. But it does not and , even worse, the focus sometimes is lost forever if any other item in the activity had no focus... so i cannot navigate using D-Pad buttons...
I want to clarify that this is NOT because of the AlertDialog that is opened after actionItem.requestFocus() is set .. I checked by commenting the Dialog opening code too .. but no luck
I am trying to do it as follows:
public void buttonClicked(View actionItem){
//Set focus on clicked button -- but this does not work
actionItem.requestFocus();
switch(actionItem.getId()){
case R.id.btnLogin:
//Show AlertDialog 1
break;
case R.id.btnInfo:
//Show AlertDialog 2
break;
case R.id.btnClose:
//Show AlertDialog 3
break;
}
}
I want the clicked button to have focus before any AlertDialog opens.. so when the AlertDialog is closed, the clicked button will have focus.
this buttonClicked event is registered with multiple buttons .. i set it as follows:
<Button
android:id="@+id/btnClose"
style="@style/button"
android:onClick="buttonClicked"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:drawableLeft="@drawable/close"
android:focusable="true"
android:text="Exit" />
<Button
android:id="@+id/btnInfo"
style="@style/button"
android:onClick="buttonClicked"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/btnClose"
android:layout_centerVertical="true"
android:drawableLeft="@drawable/information"
android:focusable="true"
android:text="About" />
the function buttonClicked is called on each button'c click but that button does not get focus...
any idea y?