Reputation: 17915
I have one main Activity with layout wrapped into ScrollView like this:
<ScrollView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1">
User can scroll up and down and there is some buttons when user scrolls down.
When user presses a button - I run code like this:
public void onClick(View view)
{
Log.d(LOG_TAG, "onClick");
TireView tiat = (TireView)view;
Intent i = new Intent(TrailerInspectionActivity.this, TireInspectionActivity.class);
i.putExtra(TireInspectionActivity.INTENT_TIRE_NUMBER, tiat.getNumber());
if (tiat.getDepth() != -1)
{
i.putExtra(TireInspectionActivity.INTENT_DEPTH, tiat.getDepth());
i.putExtra(TireInspectionActivity.INTENT_PRESSURE, tiat.getPressure());
}
TrailerInspectionActivity.this.startActivityForResult(i, REQUEST_CODE_TIRE_INSPECTION_ACTIVITY);
}
TireInspectinActivity starts and shows like popup - I use theme.Dialog
for that.
As soon as user clicks and popups show up - main activity ScrollView scrolls all way up. Is there any way to prevent this from happening?
Upvotes: 0
Views: 842
Reputation: 1037
I had the same problem.
What happened is that an EditText at the top of the ScrollView had focus. When the new activity started, the ScrollView scrolled up to make it visible.
The solution I found is to give focus to the container of my Button before calling startActivityForResult() with requestFocus() (It must be focusable).
That way, the View that has focus is visible and the ScrollView does not scroll back up.
Upvotes: 1
Reputation: 16397
You should record the current position of your ScrollView (getScrollY) and restore that in onResume for your activity.
Upvotes: 0