-3

I have a activity in Android TextView followed ListView again TextView. The content of first TextView fills the whole screen and in order to see the ListView and second TextView the user has to scrolldown. Now I wish to show the second TextView when activity start instead of first TextView.

TextView1 when activity starts

when user scrolldown ListView and TextView2 are visible

Instead I want TextView2 to be visible when activity starts.

EDITED

Sample code as per advice of @Urban

public class FocusTestActivity extends Activity {
private static final String TAG = "FocusTestActivity";
ScrollView scroll;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView text1 = (TextView) findViewById(R.id.text1);
    TextView text2 = (TextView) findViewById(R.id.text2);
    TextView text3 = (TextView) findViewById(R.id.text3);
    String hello = "We provide services to K-12 education sector."
            + "Our services include Feasibility report, Marketing, Curriculum design"
            + "Teachers planning, Design and Technology, Parents expectation"
            + "management, Transport planning, Day-to-day operations and Statutory"
            + "compliances. Please find a brief introduction attached with mail. Also visit"
            + "www.wissenways.com We can help you with overall process of setting-up school. We have"
            + "experience include establishing International, pre-school and CBSE"
            + "schools from scratch. Please feel free to contact if you need some help in your school venture."
            + "Best of Luck!<br/><br/>";

    text1.setText(Html.fromHtml(hello));
    text2.setText(Html.fromHtml(hello));
    text3.setText(Html.fromHtml(hello));
    ScrollView scroll = (ScrollView) findViewById(R.id.scrollcontainer);
}

public void onStart() {
    super.onStart();
    Log.d(TAG,"Inside onStart");
    scroll.post(new Runnable() {

        @Override
        public void run() {
            scroll.fullScroll(ScrollView.FOCUS_DOWN);
        }
    });
}

}

XML Code

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/scrollcontainer"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   <LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:id="@+id/text1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    android:textSize="17sp"/>
<TextView  
    android:id="@+id/text2"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    android:textSize="17sp"/>
<TextView  
    android:id="@+id/text3"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    android:textSize="17sp"/>
</LinearLayout>
</ScrollView>

LOGCAT output:

LogCat Output

another LogCat OutPut

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166

3 Answers3

2
getScrollView().post(new Runnable() {

    @Override
    public void run() {
        getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
    }
});

Using this code in the onCreate should start the scrollview (in which your list and two text views are) at the bottom position. I dont know why you would want to do that, and im guessing there could be a better way to do what you want rather than forcing the scroll position to the bottom, but anyways...
This is the question from where the above code is taken from, you couldve searched for it.

Hope this helped.

Community
  • 1
  • 1
Urban
  • 2,201
  • 24
  • 52
1

Here are 3 simple options i can give you:

  1. Change there places

  2. Make another activity with the second textview and launch that activity first then show you current one

  3. Show a Toast with the text in the second textview at the start of your activity (problem with this one is the user closes it and you want to show it again or user wants to see it again you need to launch a new toast)

I don't fully understand your difficulty with this problem

EDIT: when must the first textview display at the top? if never just do the first option :\ if under some event, have a empty textview at the top and at the bottom and by code change it's text to what you want at the moment you want

Hugo Alves
  • 1,555
  • 2
  • 18
  • 41
  • I have tried to explain my point by adding few images. Any of your suggestions don't solve my problems. The order of View has to be TestView1ListviewTextView2 and when activity starts TextView2 should be on screen and user should be able to upscroll to see TextView1.Thanks. – Gaurav Agarwal Nov 30 '11 at 18:25
0

You could also use in your xml file a RealtiveLayout

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView 
    android:id="@+id/txtview2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<ListView 
    android:id="@id/android:list"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_below="@id/textview2/>
<TextView 
    android:id="@+id/txtview1"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_below="@id/android:list"/>

</RelativeLayout>
AlexAndro
  • 1,918
  • 2
  • 27
  • 53