Parthiban M Parthiban M - 23 days ago 8
Android Question

Declaring autolink in TextView hides the text...!

I'm trying to define autolink = "web" for a TextView. Surprisingly when I declare this, the text in the TextView goes hidded and gets visible only on the first click. This is so astonishing I've the same functionality in many part of my application where it works fine. This is the only place where I couldn't find what the problem is.

Please help me with a solution:

Here's my TextView XML code:

<TextView
android:id="@+id/details_webAddress_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/details_location_textView"
android:drawableLeft="@drawable/icon_website_earth"
android:drawablePadding="5dp"
android:gravity="center"
android:padding="5dp"
android:singleLine="true"
android:autoLink="web"
android:text="www.google.com"
android:visibility="visible" />


Following is the TextView where the autolink works well:

<TextView
android:id="@+id/websiteAddress_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:padding="5dp"
android:singleLine="true"
android:text="www.stackoverflow.com" />

Answer

try use:

TextView textLink = (TextView) findViewById(R.id.details_webAddress_textView);
textLink.setVisibility(View.INVISIBLE);
Button buttonDetails = (Button) findViewById(R.id.button);

buttonDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textLink.setVisibility(View.VISIBLE); // text visible on firt click
                String url = "http://www.example.com";
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i); // open link with default browser
            }
        });