So I have an app that checks for various requirements and the checking process is visualized with a ProgressBar. On first start, it looks just like it should. However, if I start another Activity with startActivityForResult() (in this case the Accessibility Settings), the app initializes the whole process again, but somehow both ProgressBars look very weird (see video below).
Layout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="20dip"
android:layout_marginLeft="20dip"
android:layout_marginTop="20dip"
android:orientation="horizontal"
android:paddingLeft="5dip" >
<FrameLayout
android:layout_width="48dip"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/checkImage2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerInside"
android:visibility="invisible" />
<ProgressBar
android:id="#+id/checkProgess2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" />
</FrameLayout>
<TextView
android:id="#+id/checkText2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dip"
android:gravity="center_vertical"
android:text="Checking for Service..." />
</LinearLayout>
Initializing (after OnCreate and OnActivityResult)
private void initActivity() {
imageRoot.setVisibility(ImageView.INVISIBLE);
imageService.setVisibility(ImageView.INVISIBLE);
progRoot.setVisibility(ImageView.VISIBLE);
progService.setVisibility(ImageView.VISIBLE);
textRoot.setText("checking for root..."); //TODO
textService.setText("checking for service..."); //TODO
layoutInfo.setVisibility(LinearLayout.GONE);
setResult(Activity.RESULT_CANCELED);
CheckForRoot checkRootTask = new CheckForRoot();
checkRootTask.execute(AppName.valueOf(getIntent().getStringExtra(APPNAME)));
}
Do you have any idea what the cause for the problem could be?
Have a look at the video
Okay, I got it working with changing the FrameLayout's
android:layout_height="fill_parent"
to
android:layout_height="48dip"
Still, I have no idea why this happened - in case you know why, please let me know!
Related
First off let me apologize for any layout/formatting errors, I'm doing this on my cell.
That being said, I cannot for the life of me figure out what is wrong with the below xml. With it in my layout file, the app crashes on load, but if I cut it out, the app loads and runs fine. Any help in figuring out the problem would be greatly appreciated.
Note: The drawables are all .jpg files in the drawable folder.
Note: This section is cut from within another vertical linearlayout
Not sure if can/how to copy logcat from Aide. However, the logcat finally popped and it is an out of memory exception. I will try reducing the image size and come back.
<TextView
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:text="Current Favorites"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_height="100dp"
android:layout_width="wrap_content"
android:src="#drawable/mia_sollis"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Mia Sollis"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_height="100dp"
android:layout_width="wrap_content"
android:src="#drawable/pepper_kester"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Pepper Kester"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_height="100dp"
android:layout_width="wrap_content"
android:src="#drawable/jayme"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Jayme Langford"/>
</LinearLayout>
</LinearLayout>
The possible answer is,
<ImageView
android:layout_height="100dp"
android:layout_width="wrap_content"
android:src="#drawable/mia_sollis"/>
image "mia_sollis" is too big and hence is giving out of memory error.
Try out with smaller size image, it will solve your problem.
Possible reasons based on your XML layout:
1) You forgot to add this on top of your layout file
xmlns:android="http://schemas.android.com/apk/res/android"
2) Second and the most important
You have multiple root tag, TextView and LinearLayout both of them is your root. However, you MUST have one root layout and inside it, do what ever you want.
Cheers!
You have to post your Log
I guess
maybe the size of images is too big for your app memory.
add this to your Application tag in Manifest
<application
.......
android:largeHeap="true"
........ >
So There was a layout I wanted changed. So I added a linear layout to it and somehow it crashed code that wasn't even slightly related to it. So here Ill post some code.
Here is my main file and Ill point where the crash happens.
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.layoutLogin);
gbtnSignUp = FindViewById<Button>(Resource.Id.btnSignUp);
gbtnSignIn = FindViewById<Button>(Resource.Id.btnSignIn);
gbtnSignUp.Click += gbtnSignUp_Click;
gbtnSignIn.Click += gbtnSignIn_Click; // here is where it crashes
}
Now my layout. Ill pinpoint which part I add adds the crash.
<?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:weightSum="100"
android:layout_height="fill_parent">
<ListView
android:layout_weight="80"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#drawable/ListViewHighlight"
android:id="#+id/companyListView" />
<ProgressBar
android:layout_weight="10"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#drawable/ListViewHighlight"
android:id="#+id/progressBar1" />
<LinearLayout// just from this linear layout existing it causes a crash
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:weightSum="100"
android:id="#+id/linearLayout1">
<TextView
android:text="Text"
android:layout_width="0dp"
android:layout_weight="10"
android:layout_height="match_parent"
android:id="#+id/textView1" />
<ImageButton
android:src="#drawable/defaultAdd"
android:layout_width="0dp"
android:layout_weight="90"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:id="#+id/imageButton1" />
</LinearLayout>
</LinearLayout>
This layout isnt even linked to the view that is causing the crash. Heck I've even removed all references to this view from within the project and it still crashed.
here is the error message forcing me to break at the line I specified.
System.NullReferenceException: Object reference not set to an instance of an object
Also I can comment this line out, yet itll make it able to run but ill still be able to press the button which then does some very bizzare behaviour, which I shouldn't be able to press it to begin with.
xml of login button
<Button
android:text="Sign In"
android:layout_width="match_parent"
android:layout_weight="15"
android:layout_height="0dp"
android:id="#+id/btnSignIn"
android:textSize="25sp"
android:background="#drawable/ButtonSignInStyle"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
Your layout does not contain buttons with the ids btnSignUp and btnSignIn. You need to add them or remove the 4 lines in your activity code.
Missing in your layout
<Button
android:id="#+id/btnSignUp"
.../>
<Button
android:id="#+id/btnSignIn"
.../>
Actually this problem was some messed up situation that happened when I exported my program in order to move it to another folder. I copied and pasted my files to my old version in its original folder and it worked perfectly. So if anyone has moved files in a not so great way it may cause unforeseen problems that don't make sense like this one.
I am trying to show a pair of hidden buttons (using setVisibility(View.VISIBLE), within a RelativeLayout), but it doesn't always work. The button shows OK on a Galaxy Tab 10.1" but not in a smaller tablet (not sure which model), nor on an Android 4.0 emulator.
I randomly discovered that, for a certain TextView t, the following code causes the buttons to become visible:
t.setText(t.getText());
...
button.setVisibility(View.VISIBLE);
t is located in the same RelativeLayout but is not related to the buttons (their locations are independent and non-overlapping).
Edit: In case some Android dev wants to track this down...
I was able to reduce the code to the following layout that exhibits the problem on an Android 4.0.3 emulator but not a Galaxy Tab. I found that I need a SurfaceView or the problem does not occur (for example, change it to TextView and the problem disappears).
<?xml version="1.0" encoding="utf-8"?>
<!-- layout/test.xml -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<SurfaceView
android:id="#+id/mapCtrl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/bottomPanel"
android:text="Placeholder"
android:layout_marginTop="18dip" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/map_mode_title" />
<!--=================================================-->
<!-- Bottom bar: current road name and current speed -->
<LinearLayout
android:id="#+id/bottomPanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f228"
android:orientation="horizontal"
android:textColor="#ffff" >
<Button
android:id="#+id/btnNavMode"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="3dip"
android:textColor="#fff"
android:text="Switch to\nNav Mode" />
<RelativeLayout
android:id="#+id/currentStreetPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onClick"
android:clickable="true"
android:orientation="vertical" >
<TextView
android:id="#+id/currentStreetHdg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Current street"
android:textColor="#fff"
android:textSize="10dip" />
<TextView
android:id="#+id/currentStreet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/currentStreetHdg"
android:layout_marginTop="-8dip"
android:singleLine="true"
android:text="Current street"
android:textColor="#fff"
android:textSize="30dip" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff606060"
android:orientation="vertical" >
<TextView
android:id="#+id/yourSpeedHdg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="3dip"
android:text="Your speed"
android:textColor="#fff"
android:textSize="10dip" />
<TextView
android:id="#+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/yourSpeedHdg"
android:layout_marginLeft="3dip"
android:layout_marginTop="-8dip"
android:text="0"
android:textColor="#fff"
android:textSize="30dip" />
<TextView
android:id="#+id/speedUnit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/speed"
android:layout_marginLeft="5dip"
android:layout_toRightOf="#+id/speed"
android:text="kph"
android:textColor="#fff"
android:textSize="18dip" />
</RelativeLayout>
</LinearLayout>
<!--================-->
<!-- On-map buttons -->
<Button
android:id="#+id/btnClearRoute"
android:background="#F00"
android:textColor="#fff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear\nroute"/>
<ZoomControls
android:id="#+id/zoomControls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/mapCtrl"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-25dip"
android:orientation="horizontal" />
<Button
android:id="#+id/btnFindRoute"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/mapCtrl"
android:layout_alignParentRight="true"
android:layout_marginRight="2dip"
android:layout_marginBottom="65dip"
android:text="Route to selected location"
android:textSize="17dip"/>
<Button
android:id="#+id/btnUnselect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btnFindRoute"
android:layout_alignTop="#+id/btnFindRoute"
android:layout_alignParentLeft="true"
android:layout_marginLeft="2dip"
android:text="Unselect" />
<LinearLayout
android:id="#+id/showMePanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btnFindRoute"
android:layout_alignRight="#+id/btnFindRoute"
android:layout_alignLeft="#+id/btnFindRoute"
android:padding="4dip"
android:background="#bbbb"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show me..."
android:textColor="#fff"/>
<Button
android:id="#+id/btnShowVehicle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My car"/>
<Button
android:id="#+id/btnShowRoute"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The route"/>
<Button
android:id="#+id/btnShowDestination"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Destination"/>
<Button
android:id="#+id/btnShowMap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The map"/>
</LinearLayout>
</RelativeLayout>
The Activity class simply toggles the visibility of the two buttons when any of the buttons are clicked. Again, on some devices it works, on others it does not.
package mentor.simplegps;
import android.app.*;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
public class TestActivity extends Activity implements View.OnClickListener
{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.test);
boilerplate();
setVisibilities();
}
Button _btnShowMap, _btnShowVehicle, _btnShowRoute, _btnShowDestination;
Button _btnUnselect, _btnFindRoute, _btnNavMode;
TextView _title;
void boilerplate()
{
_btnUnselect = attachBtn(R.id.btnUnselect);
_btnShowMap = attachBtn(R.id.btnShowMap);
_btnShowVehicle = attachBtn(R.id.btnShowVehicle);
_btnShowRoute = attachBtn(R.id.btnShowRoute);
_btnShowDestination = attachBtn(R.id.btnShowDestination);
_btnFindRoute = attachBtn(R.id.btnFindRoute);
_btnNavMode = attachBtn(R.id.btnNavMode);
_title = (TextView)findViewById(R.id.title);
}
private Button attachBtn(int btnId) {
Button b = (Button)findViewById(btnId);
b.setOnClickListener(this);
return b;
}
boolean haveSel;
public void onClick(View v)
{
haveSel = !haveSel;
setVisibilities();
}
void setVisibilities()
{
_btnFindRoute.setVisibility(haveSel ? View.VISIBLE : View.INVISIBLE);
_btnUnselect.setVisibility (haveSel ? View.VISIBLE : View.INVISIBLE);
// Fixes the problem
//_title.setText(_title.getText());
}
}
SurfaceView is the sole culprit (of course, this also applies to GLSurfaceView, RSSurfaceView and VideoView, all of which inherits from SurfaceView). It exposes lots of weird behaviours when dealing with other views on top of it. Playing with View.setVisibility() is one of those issues. Clearly, SurfaceView has not been designed to be used with other views (even though the official doc says it ought to be) but as a standalone view for videos, games or OpenGL stuffs.
For the visibility issue, I've found that using View.GONE instead of View.INVISIBLE resolve it. If you don't want to use GONE, try changing the focus for example (and back to the one that had focus before), or changing other states. The goal is to wake up the underlying UI system somehow.
In short: when something weird happens with your views and you have a SurfaceView (or subclass) somewhere, try replacing it with something else so you don't lose hours searching what you're doing wrong when you're doing it right (and no false beliefs). This way, you know SurfaceView is to blame and you can hack around it with beautiful comments to piss on it without qualms.
For the record: I had this problem, tried a bunch of random stuff (thanks Alex!), and in my case what solved it was doing seekBar.requestLayout() directly after the setVisible on the very seekbar that was refusing to show.
This is my Solution
setAlpha(0)
btnName.setAlpha(0)
Is working for all views like => Buttons - Images - Texts and ...
In my case View.VISIBLE/View.GONE was not working always. When I switched my toggle to View.VISIBLE/View.INVISIBLE it started to work as intended.
I (annoyingly) had similar difficulty with having a button on top of a SurfaceView preview and had to put the Button in a RelativeLayout and make the RelativeLayout VISIBLE/INVISIBLE. Might be worth a shot for anyone else having the same issue.
...And I also had to programatically call the layout to be brought to from: buttonLayout.bringToFront() right after findViewById.
Within my main.xml, I have a table that has 2 columns and 2 rows; one for latitude & longitude and their associated values. I want them to be centered within their columns, and from my readings it seemed the best way to do that is with layout_weight="1" and gravity="center". This did work most of the time, but since I have made changes elsewhere in the code, now none of the items in gps_layout are centered unless the configuration is changed, in this case when I change the orientation by rotating the phone.
I know that rotation causes the app to go through its lifecycle (also is there a shorthand for talking about that other than calling it rebirth?) but I cannot understand what is different about the app after the first run, except for its saved state ... which would not seem to have much effect on centering. Thanks! Sorry if I did not format this question correctly, I have been trolling SO for awhile but this is my first question.
<TableLayout
android:id="#+id/gps_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
>
<TableRow>
<TextView
android:layout_column="1"
android:id="#+id/lat_text"
android:text="latitude: "
android:layout_weight="1"
android:gravity="center"
/>
<TextView
android:id="#+id/lon_text"
android:text="longitude: "
android:layout_weight="1"
android:gravity="center"
/>
</TableRow>
<TableRow>
...etc...
</TableRow>
</TableLayout>
Since I couldn't reproduce your error, I'd suggest you give a try to a different layout (with the same supposed resulting display aspect), like:
<LinearLayout android:id="#+id/gps_layout" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentTop="true" android:layout_alignBottom="#id/acquire"
android:visibility="invisible">
<LinearLayout android:orientation="vertical" android:layout_weight="1"
android:layout_height="wrap_content">
<TextView android:id="#+id/lat_text"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="latitude: "
android:gravity="center" />
<TextView android:id="#+id/lat_data"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="(lat goes here)"
android:gravity="center" />
</LinearLayout>
<LinearLayout android:orientation="vertical" android:layout_weight="1"
android:layout_height="wrap_content">
<TextView android:id="#+id/lon_text"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="longitude: " android:gravity="center" />
<TextView android:id="#+id/lon_data"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="(lon goes here)"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
Hopefully it will solve the problem on your cy 7.0.1.
Update
Some advises regarding your code:
In the MyLocationListener you shouldn't set every time the visibility of the two layout, this way it would be more effective:
#Override
public void onLocationChanged(Location loc)
{
if (acquire_view.getVisibility() == View.VISIBLE)
{
acquire_view.setVisibility(View.INVISIBLE);
gps_view.setVisibility(View.VISIBLE);
}
}
also, in onProviderEnabled method, and everywhere where you set the visibility of one layout (acquire_view/gps_view), you should also set for the other as well.
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