开发者

Android - Basic question - link TextView to open new page (internal)

开发者 https://www.devze.com 2023-02-04 04:05 出处:网络
Probably a really basic answer to this but google is throwing up nonsense. 开发者_StackOverflow社区

Probably a really basic answer to this but google is throwing up nonsense. 开发者_StackOverflow社区

Ok, so i have a bunch of nested linear layouts, each one contains a textview and an imageview. What i want is my textview to be linked so that when a user clicks on the text, it will take the user to a new page that is in the same project. Not a website or anything.

Appreciate any help!!


You can add an onTouchListner to you TextViews and when user clicks on it you simply launch a new Activity. Google for adding touch listeners and then for launching activities and you will find the components you need.

Activities are like pages in Android apps.


Yeah, Juhani's right. You can use an onTouchListener. It's actually really simple. Just create a new .java file that loads the Layout you want in the onCreate. In the code you just use this line for the onClickListener:

            startActivity(new Intent(this, newjavafile.class));

and add the new Activity to your manifest. I had something close to this exact problem. The nice thing about doing it this way is the back button on the phone/device works to get you back to the main screen.


First write attribute in TextView Like,

<TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:text="Click Here" />

And in Java File

TextView text= (TextView) findViewById(R.id.text);

        text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(this,SecondActivity.class));
            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消