How to create unfocussed,enabled edittextbox in android
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:
setCon开发者_运维百科tentView(R.layout.main); edit=(EditText)findViewById(R.id.edit); but=(Button)findViewById(R.id.but); edit.setFocusable(false);
xml:
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.
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
精彩评论