1

i've created one searchEditBox and a button.Initially when the page loads.,the searchEditBox will be focussed with orange color mark automatically.when i use searchValue.setFocusable(false);.,its unfocussed but i couldnt able to type anything on that box(Box will be disabled).How could i recover this probs.?

java:

setContentView(R.layout.main); edit=(EditText)findViewById(R.id.edit); but=(Button)findViewById(R.id.but); edit.setFocusable(false);

xml:

sanjay
  • 2,590
  • 17
  • 55
  • 88

2 Answers2

1

Hopefully this will solve your problem. Add the android:focusableInTouchMode="true" to your linearLayout that holds your EditText in your mail.xml file.

ie:

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearLayout"
android:focusableInTouchMode="true">

This worked for me. Very simple solution.

Dave
  • 3,178
  • 5
  • 28
  • 44
0

comment your edit.setFocusable(false);

use searchValue.requestFocus() to set focus on EditText. It will work for you.

Check the following code.

Activity

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.admob);

         // Lookup R.layout.main
       EditText edit = (EditText) findViewById(R.id.edit);

       Button but=(Button)findViewById(R.id.but);
//       edit.setFocusable(false);
       edit.requestFocus();
    }

admob.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/linearLayout">

<EditText android:id="@+id/edit"
        android:layout_width="250px" 
        android:layout_height="wrap_content" 
       />
        <Button android:id="@+id/but"
         android:layout_width="80px"
         android:layout_height="wrap_content"
         android:text="click"/>
</LinearLayout>

Donot forget to vote if my response is helpful for you.

Thanks Deepak

Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243