Showing posts with label Focus. Show all posts
Showing posts with label Focus. Show all posts

Friday, January 18, 2013

Android Development How to Set Focus

You ever need to set focus for a control on your GUI.
You could design a GUI interface for your Android application but, you need to set the focus to one specific control on start-up.  In this example I am using a Button control for that.  You have two options, option one: add the focus option in the xml file that describes your GUI, or option two: add the code that does the same thing in option one but can be used in run time instead of only once on start-up.

Option One:
Add this part to your xml GUI file



<Button
android:id="@+id/open_bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open_comm"
android:onClick="onClick"
android:focusableInTouchMode="true"
>
<requestFocus/>
</Button>



Option Two:
Add this to the Activity module:

static Button Open_Button;

Open_Button = (Button) findViewById(R.id.open_bt);

Open_Button.setFocusableInTouchMode(true);
Open_Button.requestFocus();


More information will be added, and screen shots...