I have a Main Activity That has a Clickable Link that launches a Activity. Right now what is showing is "Click Here" in a text view. I would like to change it to : "To see Evacuation Routes - Click Here" With the "Click Here" being the underlined text. Below is the Code I currently have.
activity_main.xml
<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: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=".MainActivity" >
<TextView android:id="@+id/txtView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtView_5"
android:text=""
android:textSize="20sp"
android:textStyle="bold"/>
</RelativeLayout>
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean isGPS = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
AsyncRouteNames asyncRouteNames = new AsyncRouteNames();
asyncRouteNames.execute();
String mapStr = "Click Here";
SpannableString mapContent = new SpannableString(mapStr);
mapContent.setSpan(new UnderlineSpan(), 0, mapStr.length(), 0);
final TextView mapTxtView = (TextView) findViewById(R.id.txtView1);
mapTxtView.setText(mapContent);
mapTxtView.setTextColor(Color.BLUE);
Linkify.addLinks(mapTxtView, Linkify.ALL);
ConnectivityManager cm = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isMobile = false;
if (activeNetwork != null && activeNetwork.isConnected()){
isMobile = true;
}
if (isMobile){
mapTxtView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.this.startActivity(new Intent(MainActivity.this, EvacRouteTableActivity.class));
}
});
} else {
mapTxtView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.this.startActivity(new Intent(MainActivity.this, NoConnectionActivity.class));
}
});
}
}
You can add a LinearLayout with orientation: "horizontal" and add both textviews in it.
<LinearLayout
...
android:orientation="horizontal">
<TextView .../>
<TextView .../>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With