Android: How to use Buttons in Preference Screen - android

I'd like to provide a Button in the PreferenceActivity. The user should be able to set a
time (e.g. via TimePicker), but there's no ButtonPreference or something like that. I don't want to use EditTextPreference.
So do I have to use a default Button in the PreferenceActivity and save the settings for it manually?
Regards,
cody

Create a custom DialogPreference that incorporates a TimePicker widget. No button required. Should be under 100 lines of code.
Here is a sample project showing, among other things, a custom ColorPreference.

Create a different layout including your custom controls and include ListView on top, see the example below
// extra_settings.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView
android:id="#+id/feedback"
android:text="Feedback"
/>
<Button
android:id="#+id/about"
android:text="About"
/>
</LinearLayout>
Once this done, onCreate method of your class which is extended from PreferenceActivity add following line
setContentView(R.layout.settings_extras); //name of your layout
bind OnClickListener
View.OnClickListener feedbackPageRedirect = new View.OnClickListener()
{
public void onClick(View v)
{
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback ");
startActivity(emailIntent);
}
};

You can put the button in the activity_layout.xml . For example, if "Activity_Setup.java" is your setup activity, "activity_setup.xml" is its layout, and "myprefs.xml" is the file where your preference layout is stored, then
your should put the button in "activity_setup.xml" under the list, most preferable in a TableRow, like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/llprefs">
<ListView
android:id="#+id/android:list"
android:tag="lvprefs"
android:layout_width="match_parent"
android:layout_height="0.0dp"
android:layout_weight="1" >
</ListView>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
>
<Button
android:id="#+id/btRegister"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/IdonothaveA"
android:onClick="onClick"
/>
<Button
android:id="#+id/btForgot"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/Iforgot"
android:onClick="onClick" />
<!--
<Button
android:id="#+id/btContact"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/Contact"
android:onClick="onClick" />
-->
</TableRow>

Related

android - set text for spinner in <include />

I would like to set text for the spinners in the layout reused. However, only the first spinner is set. How to set text for all spinners with same id?
Also, I would like to ask how add another skillfield.xml to fragment_skill.xml when clicking the imageview?
Thank you.
fragment_skill.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/skillInfo" >
<RelativeLayout
android:id="#+id/OCC"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/occ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="#string/occSkill"
android:textSize="20sp" />
<TextView
android:id="#+id/occPt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_toEndOf="#id/occ"
android:text=""
android:textSize="20sp" />
<include
android:id="#+id/oocSkill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/occ"
layout="#layout/skillfield" />
<ImageView
android:id="#+id/addOccSkill"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_below="#id/oocSkill"
android:contentDescription="#string/delSkill"
android:src="#android:drawable/ic_input_add" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/ORI"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/OCC" >
<TextView
android:id="#+id/ori"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="#string/oriSkill"
android:textSize="20sp" />
<TextView
android:id="#+id/oriPt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_toEndOf="#id/ori"
android:text=""
android:textSize="20sp" />
<include
android:id="#+id/oriSkill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ori"
layout="#layout/skillfield" />
<ImageView
android:id="#+id/addOriSkill"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_below="#id/oriSkill"
android:contentDescription="#string/delSkill"
android:src="#android:drawable/ic_input_add" />
</RelativeLayout>
</RelativeLayout>
skillfield.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/addSkillField" >
<Spinner
android:id="#+id/selectSkill"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp" />
<TextView
android:id="#+id/skillPt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text=""
android:textSize="20sp" />
<ImageView
android:id="#+id/addSkill"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="bottom"
android:contentDescription="#string/delSkill"
android:src="#android:drawable/ic_delete" />
</LinearLayout>
In MainActivity.class
skill = (Spinner) findViewById(R.id.selectSkill);
ArrayAdapter<CharSequence> skillAdapter = ArrayAdapter.createFromResource(context, R.array.skills, R.layout.spinner);
skillAdapter.setDropDownViewResource(R.layout.spinner_down);
skill.setAdapter(skillAdapter);
how to setup Spinner with the same ID
It is true that if you do this:
skill = (Spinner) findViewById(R.id.selectSkill);
You will be only able to get the first Spinner. I don't think you can add new Spinner dynamically by using <include>.
Here's the main idea of how to achieve what you need:
In fragment_skill.xml, you need to add an empty container view. This container should be inserted in the place you want to add your Spinner every time the button is clicked. This container will hold your Spinners that are added.
Let's say you want to insert here:
<RelativeLayout...>
<TextView.../>
<TextView.../>
<!-- here is where you want to insert your Spinner -->
<ImageView.../>
</RelativeLayout...>
So you add a LinearLayout at that spot, like this:
<RelativeLayout...>
<TextView.../>
<TextView.../>
<LinearLayout
android:id="#+id/container"
android:orientation="vertical
... />
<ImageView.../>
</RelativeLayout...>
You can add any other type of layout, depending what you need, it doesn't have to be LinearLayout. After that, you grab that LinearLayout from your activity/fragment like this:
LinearLayout mContainer; // make this instance variable
mContainer = (LinearLayout)findViewById(R.id.container);
Also grab the button so that you can set up a listener, let's assume it's called Button mButton:
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
addNewSpinner();
});
So when the button is clicked, you will call addNewSpinner(). Now, make a method called addNewSpinner(). Inside, the method, we will be inflating skillfield.xml. The method should look something like this:
public void addNewSpinner(){
View view = getLayoutInflater().inflate(R.layout.skillfield, null);
Spinner skill = (Spinner) view.findViewById(R.id.selectSkill);
ArrayAdapter<CharSequence> skillAdapter = ArrayAdapter.createFromResource(context, R.array.skills, R.layout.spinner);
skillAdapter.setDropDownViewResource(R.layout.spinner_down);
skill.setAdapter(skillAdapter);
mContainer.addView(skill);
}
If you are not sure what inflate means, here is the explanation:
Instantiates a layout XML file into its corresponding View objects.
Hope it helps!

When using setOnClickFillInIntent and setPendingIntentTemplate, click events never occur

I am working on an Android home screen app widget that fills a listview with custom defined row layouts.
The listview gets populated correctly, but when I click any of the items, nothing happens.
Here is some of the relevant parts
From the AppWidgetManager's onUpdate()
...
final Intent contactIntent = new Intent(context, ContactService.class);
contactIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
contactIntent.setData(Uri.parse(contactIntent.toUri(Intent.URI_INTENT_SCHEME)));
view.setRemoteAdapter(widgetId, R.id.listview, contactIntent);
//works fine up to here, populates ListView
//Set up pendingIntentTemplate
final Intent contactClick = new Intent(context,ContactDial.class);
contactClick.setData(Uri.parse(contactClick.toUri(Intent.URI_INTENT_SCHEME)));
final PendingIntent contactClickPI = PendingIntent.getBroadcast(context,
0,contactClick,PendingIntent.FLAG_UPDATE_CURRENT);
view.setPendingIntentTemplate(R.id.listview, contactClickPI);
Log.d("TEMPLATE", "set template");
...
From the RemoteViewsFactory's getViewAt(int position)
final Intent i = new Intent();
final Bundle extra = new Bundle();
extra.putString("number", phoneNumber);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtras(extra);
row.setOnClickFillInIntent(R.id.contact_row,i);
Log.d("FACTORY", "Set Intent Template");
The logs show that the code was executed correctly, but for some reason it doesn't seem to register my clicks. I put a Log.d in the onCreate of the class that the intent is supposed to be sent to, but it never happens.
Here are the important parts of my layouts.
The main layout:
<LinearLayout
android:id="#+id/layout_two"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="260dp" />
<!-- Some other views -->
</LinearLayout>
The custom defined row:
<LinearLayout android:id="#+id/contact_row"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="#xml/buttoncolor_selector"
android:paddingBottom="2dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="10dip" >
<ImageView
android:id="#+id/contact_photo"
android:layout_width="#android:dimen/notification_large_icon_width"
android:layout_height="match_parent"
android:layout_marginRight="5dip"
android:src="#drawable/ic_action_person />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
android:id="#+id/contact_name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="18sp"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="marquee"
android:textIsSelectable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"/>
<TextView
android:id="#+id/contact_number"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:textIsSelectable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false" />
</LinearLayout>
</LinearLayout>
I've looked at just at just about every example I can find on the Internet, but none of the solutions have changed anything.
Please help.
In your custom defined row, try moving android:id="#+id/contact_row" down to a child view (even if it's a "useless" viewgroup that just surrounds everything else). Or, surround your top level LinearLayout with a FrameLayout. I didn't have luck having the setOnClickFillInIntent() set to target the ID on the very top level viewgroup like that.
Like so,
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:id="#+id/contact_row"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="#xml/buttoncolor_selector"
android:paddingBottom="2dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="10dip" >
<ImageView
android:id="#+id/contact_photo"
android:layout_width="#android:dimen/notification_large_icon_width"
android:layout_height="match_parent"
android:layout_marginRight="5dip"
android:src="#drawable/ic_action_person" />
........
Depending on your needs, you may be able to eat your cake and have it too, and have a non-useless viewgroup if you rearrange your layout.

I click the button ,can add a data to the listView

I set one Gribview and one listview in an Activity,In the Gridview there is a TextView and a Button,What I want do is ,when I click the button ,can add a data to the listView .and the button and listView in different layout files.
the xml code is :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:descendantFocusability="blocksDescendants"
>
<ImageView
android:id="#+id/image"
android:layout_width="180dp"
android:layout_height="160dp"
android:layout_gravity="fill"
android:padding="4dp"
android:scaleType="fitXY" />
<LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:text="prices"
/>
<TextView
android:id="#+id/prices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:text="name"
/>
</LinearLayout>
<LinearLayout android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="9" />
<Button
android:id="#+id/add"
android:layout_width="45dip"
android:layout_height="45dip"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:text="+"
android:layout_weight="0.2"
android:textSize="12pt"
/>
</LinearLayout>
</LinearLayout>
I want to realize when I click the button ,the sequence number of the image I pick can add to the listView.
ADD:
maybe I didn't say it clear.I have gridView and listView in one layout file.In the gridView I define an layout file ,which contain an ImageView and a Button.What I realize is ,when the app run,I have obtain the button's action in getView,What I want:in button events ,how to write the position values in listView.I haven't got the solution yet ,it really bother me ,thankx for any help.
ADD2:
Now I have achieved the adapter.notifyDataSetChanged()adding data in ListView.but I don't know how to obtain the string variable in Acitivity,the string variable is given by text(TextView android:id="#+id/prices") in ListView to Activity.When I refresh View(adapter.notifyDataSetChanged()),I get "0". why?could anyone help?thank a lot.
You'll need to begin by adding a ListView to your layout file, and adding a button handler.
Take a look at Dynamically add elements to a listView Android
This links to a Stack Overflow question/answer that should get you started

RelativeLayout Stack Buttons

I would like to align two buttons on the bottom of a relative layout that is wrapped inside of a linear layout.
I am unable to get the view favorites button to be on top of the search button. There is a big space as you can see in this image:
Here is my code:
<?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">
<TextView
android:text="#string/SearchRestaurantsCity"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchCity" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etRestaurantSearchCity" />
<TextView
android:text="#string/SearchRestaurantsState"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchState" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etRestaurantSearchState" />
<TextView
android:text="#string/SearchRestaurantsCategories"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchCategories" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spRestaurantSearchCategories" />
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<Button
android:text="#string/btnViewFavoriteRestaurants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnViewFavoriteRestaurants"
style="#style/ButtonText"
android:padding="5dp"
android:layout_below="btnSearchRestaurants" />
<Button
android:text="#string/btnSearchRestaurants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnSearchRestaurants"
style="#style/ButtonText"
android:layout_alignParentBottom="true"
android:padding="5dp" />
</RelativeLayout>
There are 2 things wrong with the XML.
For starters, you can't refer to the button btnSearchRestaurants before it's defined.
Secondly, you've defined btnSearchRestaurants to align-parent-bottom, and then tried to define that btnViewFavoriteRestaurants would be below that button. It should be above it (as per your description).
If you're trying to put the first button I can see inside RelativeLayout, I'd try to change the following line:
android:layout_below="btnSearchRestaurants" />
for this one:
android:layout_above="#+id/btnSearchRestaurants" />
Part of the space is reserved for all the elements of the layout I can see inside the LinearLayout,and the + is because the button btnSearchRestaurants is below so it is not created yet
I think the problem is at
android:layout_below="btnSearchRestaurants"
It should be
android:layout_below="#id/btnSearchRestaurants"
In your xml code I think you should correct this line
android:layout_below="btnSearchRestaurants"
as you want it to be above the Search Restaurants button it should be
android:layout_above="#id/btnSearchRestaurants"
I changed below to above for obvious reasons (you want it above the other button not below it) and added #id/ because you will be searching for the button id.

Why is Android TabHost stealing focus from a TextView?

I have an application using the following layout :
alt text http://img15.imageshack.us/img15/238/screenshot003xbo.png
When the app starts, the focus is on the first TextView, but if you try to type any letter in it, the focus goes directly to the tabs. It seems that I am not the only one fighting with this issue, and maybe this is related to the following:
http://groups.google.com/group/android-developers/browse_thread/thread/435791bbd6c550a/8022183887f38f4f?lnk=gst&q=tabs+focus#8022183887f38f4f
Anyway, have you any idea of why that happens? And of course, any workaround would be appreciated.
I post the code below to avoid overloading the question :
The 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">
<LinearLayout
android:padding="5px"
android:orientation="vertical"
android:id="#+id/task_edit_panel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50" >
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:textStyle="bold" />
<EditText android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<TabHost android:id="#+id/edit_item_tab_host"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="65px"> <!-- you need that if you don't want the tab content to overflow -->
<LinearLayout
android:id="#+id/edit_item_date_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/edit_item_geocontext_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lieu"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/edit_item_text_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px">
<EditText android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" />
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>
<!-- Bottom pannel with "add item" button -->
<LinearLayout
android:padding="5px"
android:orientation="horizontal"
android:layout_weight="1"
android:id="#+id/task_edit_panel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#E7E7E7" >
<!-- Let the height set to fill_parent until we find a better way for the layout -->
<Button android:id="#+id/item_edit_ok_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="#string/ok"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1" />
<Button android:id="#+id/item_edit_cancel_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="#string/cancel"
style="?android:attr/buttonStyleSmall"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
And the Java code :
TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
// don't forget this setup before adding tabs from a tabhost using a xml view or you'll get an nullpointer exception
tab_host.setup();
TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");
ts1.setIndicator(getString(R.string.when), getResources().getDrawable(R.drawable.ic_dialog_time));
ts1.setContent(R.id.edit_item_date_tab);
tab_host.addTab(ts1);
TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");
ts2.setIndicator(getString(R.string.where), getResources().getDrawable(R.drawable.ic_dialog_map));
ts2.setContent(R.id.edit_item_geocontext_tab);
tab_host.addTab(ts2);
TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");
ts3.setIndicator(getString(R.string.what), getResources().getDrawable(R.drawable.ic_menu_edit));
ts3.setContent(R.id.edit_item_text_tab);
tab_host.addTab(ts3);
tab_host.setCurrentTab(0);
Well, definitly a bug : http://code.google.com/p/android/issues/detail?id=2516.
Hope it will be fixed in the next release because this is a really anoying issues for complex apps with an advanced layout.
I was facing the same kind of issue with HoneyComb but found a very simple solution. So I thought it can be helpful for someone to share my experience. Everytime when a tab is clicked, the focus is on Edit Text and you can actually type with hard keyboard but soft keyboard never pops up. Even with below code, it didnt solve the issue:
input1.requestFocusFromTouch();
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(input1, InputMethodManager.SHOW_FORCED);
Solution:
In the main class where you are handling Tabs, just write below Java code:
myTabHost.setOnTabChangedListener(new OnTabChangeListener(){
public void onTabChanged(String tabID) {
myTabHost.clearFocus();
}
});
If it isn't related to that other bug you pointed out (and it looks like it probably is) and if you're experiencing this on on of the G1s (and not the emulator) I suspect your problem is that the focus either isn't being frozen before the orientation change (when you fold out the keyboard and go into landscape mode) or unfrozen after the view is recreated. You could try Overriding the activity's onSaveInstanceState() and onRestoreInstanceState() methods to save/restore the focus.
this example show how to fix this issue:
userNameEditText.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
userNameEditText.requestFocusFromTouch();
return false;
}
});
after adding all the specs add requestFocus method to your edittext in java file

Categories

Resources