Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用textView作为按钮_Java_Android - Fatal编程技术网

Java 使用textView作为按钮

Java 使用textView作为按钮,java,android,Java,Android,这是照片。我想从目录中单击“体征和症状”,通过单击直接跳到“体征和症状”段落。请解决我的问题。这是我的密码 <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="

这是照片。我想从目录中单击“体征和症状”,通过单击直接跳到“体征和症状”段落。请解决我的问题。这是我的密码

<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>
使用
android:onClick=“”
android:Clickable=“true”

要使文本视图成为按钮,请使用安卓:onClick=“”和安卓:Clickable=“true”


要使文本视图成为按钮,您可以在
Textview

上使用
OnclickListener
您可以在
Textview

上使用
OnclickListener
,然后在
OnClick
上使用以下方法,其中,textViewOver是您需要跳转的上方的
TextView

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();
        }
    }
);

希望有帮助

您可以在
TextView
上使用
OnClickListener
,然后在
OnClick
上使用以下方法,其中TextView是您需要跳转的
TextView
上方的

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();
        }
    }
);

希望有帮助

这是代码,但仍然给我错误,直到我错在哪里

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);
                }
            }

    }

这是代码,但仍然给我错误,直到我哪里我错了

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);
                }
            }

    }


以及如何编码从目录直接跳到段落?view.smoothScrollToPosition(内容位置);你能告诉我这个职位我应该写些什么吗??请看我的布局。我已经给出了id标志和症状图。以及如何编码从目录直接跳转到段落?视图。smoothScrollToPosition(内容位置);你能告诉我这个职位我应该写些什么吗??请看我的布局。我已经给了身份证签名和签名。是的,我知道,但是标题和段落的布局是一样的。我希望,当我从目录中单击图片中给出的符号和症状时,它会自动向下滚动到同一布局中给出的段落的符号和症状??您需要聚焦相应的视图。。请按照链接雅我知道,但它在同一布局的标题和段落。我希望,当我从目录中单击图片中给出的符号和症状时,它会自动向下滚动到同一布局中给出的段落的符号和症状??您需要聚焦相应的视图。。请跟随链接,您也可以使用ListView代替多个文本视图…您也可以使用ListView代替多个文本视图…您的文本视图需要id。因此,如果您单击风险因素,例如,您可以使用findViewById查找上面的textview,在这种情况下,包含android:text=“@string/atherosclerosisdefinition”的描述textview。我应该在代码中写入textview id而不是TextViewUpper吗?TextViewUpper是变量,例如textview TextViewUpper=(textview)findViewById(R.id.definition),这是您要跳转的textview(风险因素)上方的textview。请参阅上面的java代码。还是不工作?代码中缺少了什么?请为我指出。您需要您的文本视图的id。因此,如果您单击风险因素,例如,您可以使用findViewById查找上面的textview,在这种情况下,包含android:text=“@string/atherosclerosisdefinition”的描述textview。我应该在代码中写入textview id而不是TextViewUpper吗?TextViewUpper是变量,例如textview TextViewUpper=(textview)findViewById(R.id.definition),这是您要跳转的textview(风险因素)上方的textview。请参阅上面的java代码。还是不工作?代码中缺少了什么?请给我指出。在setContentView(R.layout.atherosclerosis)之后放置TextView TvOver=(TextView)findViewById(R.id.pathophysiology_id),您需要使用findViewById获取scrollview以使用scrollview.post。。。如果您一直收到一些错误,您可以发布错误日志吗?将您的TextView TvOver=(TextView)findViewById(R.id.pathologistics_id)放在setContentView(R.layout.com)之后,您需要使用findViewById获取scrollview以使用scrollview.post。。。如果你一直收到一些错误,你能发布错误日志吗?