Reputation: 37
I have added the details inside the displayItems activity after user click the item on Listview. The question is how can I make the URL clickable so user can got to that specific website.(The details is called from csv file). Anyone can guide me?
My Listview.java
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(ShoppingMall.this, Displayitem.class);
if (adapter.getItem(position).length > 0) {
intent.putExtra(Displayitem.EXTRA_NAME, adapter.getItem(position)[1]);
intent.putExtra(Displayitem.EXTRA_STATE, adapter.getItem(position)[2]);
intent.putExtra(Displayitem.EXTRA_ADDRESS, adapter.getItem(position)[4]);
intent.putExtra(Displayitem.EXTRA_URL, adapter.getItem(position)[5]);
intent.putExtra(Displayitem.EXTRA_NUMBER, adapter.getItem(position)[6]);
intent.putExtra(Displayitem.EXTRA_MAIL, adapter.getItem(position)[7]);
}
startActivity(intent);
}
});
My displayItem.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_displayitem);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
tvMallName = (TextView) findViewById(R.id.tv_mallname);
state = (TextView) findViewById(R.id.states);
mallAddress = (TextView) findViewById(R.id.mall_Address);
url = (TextView) findViewById(R.id.url);
phone_number = (TextView) findViewById(R.id.phone_number);
mail = (TextView) findViewById(R.id.mail);
extras = getIntent().getExtras();
String malladress = extras.getString(EXTRA_ADDRESS,"");
String mallName = extras.getString(EXTRA_NAME, "");
String mallurl = extras.getString(EXTRA_URL,"-");
String mallnumber = extras.getString(EXTRA_NUMBER,"-");
String mallstate = extras.getString(EXTRA_STATE,"");
String mallmail = extras.getString(EXTRA_MAIL,"-");
mallAddress.setText(malladress);
tvMallName.setText(mallName);
state.setText(mallstate);
url.setText(mallurl);
mail.setText(mallmail);
phone_number.setText(mallnumber);
}
Upvotes: 0
Views: 35
Reputation: 1607
Put this piece of code in onClick
method of of textview. This will launch the browser with the specified URL
Intent intent= new Intent(Intent.ACTION_VIEW,Uri.parse(YOUR_URL));
startActivity(intent);
Upvotes: 1
Reputation: 1114
Methode 1 :
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
Method 2:
use android:autoLink="web"
in your TextView's xml. It should automatically convert urls click-able (if found in text)
Also include android:linksClickable="true"
Upvotes: 1