1

enter image description here

here is the picture. i want to click signs & Symptoms from the table of contents and by clicking i want it to jumps directly to the Signs and Symptoms paragraph. Please solve my this problem. here is my code.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:background="#ffffff"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Atherosclerosis"
    tools:ignore="UselessParent,ScrollViewCount" >
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<LinearLayout
     android:id="@+id/tablecontentlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#EFECCB" >
    <TextView
        android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="17sp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:text="@string/table" />
     <TextView
         android:id="@+id/definitionid"
         android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="#4682B4"
        android:text="@string/Definition" />
     <TextView
         android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="#4682B4"
        android:text="@string/RiskFactors" />
      <TextView
          android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="#4682B4"
        android:text="@string/Pathophysiology" />
      <TextView
          android:id="@+id/Signandsymptompsid"
          android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="#4682B4"
        android:text="@string/SignsandSymptoms" />
       <TextView
           android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="#4682B4"
        android:text="@string/Diagnosis" />
       <TextView
           android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="#4682B4"
        android:text="@string/Treatment" />
       <TextView
           android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="#4682B4"
        android:text="@string/Prevention" />
       <TextView
           android:layout_marginLeft="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:textColor="#4682B4"
        android:text="@string/Complications" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:layout_below="@+id/tablecontentlayout"
    android:layout_marginTop="15dp"
    android:orientation="vertical" >
        <TextView
            android:id="@+id/atherodefinition" 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Definition"
            android:background="#F5F5F5"
            android:textColor="#264177"
            android:textSize="17sp"
            android:textStyle="bold"/>
        <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/atherosclerosisdefinition"
            android:textSize="15sp"/>
          <TextView

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/RiskFactors"
            android:background="#F5F5F5"
            android:textColor="#264177"
            android:textSize="17sp"
            android:textStyle="bold"/>
        <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Modifiable"
            android:textStyle="bold"
            android:textSize="15sp"/>
        <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/modifiableatherosclerosis"
            android:textSize="15sp"/>
        <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Nonmodifiable"
            android:textStyle="bold"
            android:textSize="15sp"/>
        <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/nonmodifiableatherosclerosis"
            android:textSize="15sp"/>
          <TextView

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Pathophysiology"
            android:background="#F5F5F5"
            android:textColor="#264177"
            android:textSize="17sp"
            android:textStyle="bold"/>
        <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/pathophysiologyatherosclerosis"
            android:textSize="15sp"/>
        <TextView
            android:id="@+id/Signandsymptomsparagraph"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/SignsandSymptoms"
            android:background="#F5F5F5"
            android:textColor="#264177"
            android:textSize="17sp"
            android:textStyle="bold"/>
         <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/atherosclerosissignsandsymptoms"
            android:textSize="15sp"/>
         <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Diagnosis"
            android:background="#F5F5F5"
            android:textColor="#264177"
            android:textSize="17sp"
            android:textStyle="bold"/>
         <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Diagnosisatherosclerosis"
            android:textSize="15sp"/>
         <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Treatment"
            android:background="#F5F5F5"
            android:textColor="#264177"
            android:textSize="17sp"
            android:textStyle="bold"/>
         <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/lifestylemodification"
            android:textSize="15sp"/>
         <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/treatmentatherosclerosis"
            android:textSize="15sp"/>
         <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Prevention"
            android:background="#F5F5F5"
            android:textColor="#264177"
            android:textSize="17sp"
            android:textStyle="bold"/>
         <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Preventionatherosclerosis"
            android:textSize="15sp"/>
         <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Complications"
            android:background="#F5F5F5"
            android:textColor="#264177"
            android:textSize="17sp"
            android:textStyle="bold"/>
         <TextView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/complicationatherosclerosis"
            android:textSize="15sp"/>
    </LinearLayout>
    </RelativeLayout>
    </ScrollView>

</RelativeLayout>

my java code for this layout:

public class Atherosclerosis extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.atherosclerosis);

    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.atherosclerosis, menu);
        return true;
    }

}
Pang
  • 9,564
  • 146
  • 81
  • 122
user2592807
  • 374
  • 1
  • 2
  • 14

4 Answers4

4

Use android:onClick="" and android:Clickable="true"

to make the Textview as a button

Nambi
  • 11,944
  • 3
  • 37
  • 49
1

You can have OnclickListener on TextView

NullPointerException
  • 3,978
  • 4
  • 34
  • 52
  • 1
    ya i know that but its in the same layout the heading and paragraph. i want it that when i click sign and symptom from the table of contents as given in the picture it automatically scroll down to the sign and symptoms of the paragraph given in the same layout?? – user2592807 Jan 27 '14 at 17:33
  • You need to focus perticular view.. Please follow the link http://stackoverflow.com/questions/6831671/is-there-a-way-to-programmatically-scroll-a-scroll-view-to-a-specific-edit-text – NullPointerException Jan 27 '14 at 17:40
1

You can use OnClickListener on TextView and then use the following method on the OnClick, where textViewAbove is the TextView that is above the one you need to jump:

scrollView.post(
    new Runnable() {
        @Override
        public void run() {
            new CountDownTimer(1500, 20) {
                @Override
                public void onTick(long millisUntilFinished) {
                    scrollView.scrollTo(0, (int) (textViewAbove.getBottom()-millisUntilFinished));
                }

               @Override
               public void onFinish() {                 
               }
            }.start();
        }
    }
);

Hope it helps!

Giacomoni
  • 1,468
  • 13
  • 18
  • You will need id's for your TextViews. So if you click on Risk Factors, for example, you can use findViewById to find the textview above, in this case the description textview that has the android:text="@string/atherosclerosisdefinition". – Giacomoni Jan 27 '14 at 18:30
  • should i write textview id instead of textviewabove in your code?? – user2592807 Jan 27 '14 at 20:27
  • textViewAbove is the variable, for example TextView textViewAbove = (TextView) findViewById(R.id.atherodefinition), which is the textview above the textview that you want to jump (Risk Factors). – Giacomoni Jan 27 '14 at 22:12
  • please see the above java code. still not working? what i am missing in the code? please point it out for me. – user2592807 Jan 28 '14 at 07:25
-1

Here is the code but still give me error till me where I am wrong?

public class Atherosclerosis extends Activity{

    ScrollView scrollView;

    TextView tvabove=(TextView)findViewById(R.id.pathophysiology_id);

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @SuppressLint("NewApi")

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.atherosclerosis);
             ActionBar bar = getActionBar();
                bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#6B8E23")));
                getActionBar().setDisplayHomeAsUpEnabled(true);
                getActionBar().setHomeButtonEnabled(true); 
        TextView tv=(TextView)findViewById(R.id.Signandsymptompsid);

        tv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                scrollView.post(
                        new Runnable() {
                            @Override
                            public void run() {
                                new CountDownTimer(1500, 20) {
                                    @Override
                                    public void onTick(long millisUntilFinished) {
                                        scrollView.scrollTo(0, (int) (tvabove.getBottom()-millisUntilFinished));
                                    }

                                   @Override
                                   public void onFinish() {                 
                                   }
                                }.start();
                            }
                        }
                    );
            }
        });
        }
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.atherosclerosis, menu);
            return true;
        }
          @Override
            public boolean onOptionsItemSelected(MenuItem item) {
                // Take appropriate action for each action item click
                switch (item.getItemId()) {
                case R.id.id_search:
                    Intent newActivity0 = new Intent(this,Search.class);     
                     startActivity(newActivity0);
                    return true;
                case R.id.id_favorit:
                   return true;

                default:
                    return super.onOptionsItemSelected(item);
                }
            }

    }
JiTHiN
  • 6,548
  • 5
  • 43
  • 69
user2592807
  • 374
  • 1
  • 2
  • 14
  • Put your TextView tvabove=(TextView)findViewById(R.id.pathophysiology_id) after setContentView(R.layout.atherosclerosis), and you need to get the scrollview using findviewbyid to use scrollView.post on it... if you keep getting some error, can you post the error log? – Giacomoni Jan 28 '14 at 11:15