Tuesday, July 3, 2012

Android - Change the default focus inside a Alert dialogue

set on focus change for any object inside the dialog.

@Override
public void onFocusChange(View view, boolean hasFocus) {
// Set focus where ever you want according to your custom logic

// for example to focus on the positive button after a webview scroll
// web is the webview and the buttons are initialized inside onCreateDialog 

        if(!web.isFocused() && !positiveButton.isFocused() && negativeButton.isFocused()){
            positiveButton.requestFocus();
        }

}


Android - How to detect scroll inside webview?

Create a custom webview class which extends of course webview :)


public class CustomWebView extends WebView 

Override the following method

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) 

int l is x, int is y

Thats it :)

Android - Can not focus into objects inside listview?

listView.setItemsCanFocus(true);//self explanatory

 Edit the view that you want to add inside the listview. Add the following property.
 android:descendantFocusability="afterDescendants"

 The End :)