简体   繁体   English

我想在Android中显示超链接项目的列表。

[英]I want to display a list of hyperlinked items in Android.

Some items in the list, if clicked, will hyperlink to a URL. 如果单击列表中的某些项目,它们将超链接到URL。 If there is no URL for the associated item, then clicking it should do nothing. 如果没有相关项目的URL,则单击该项目将不执行任何操作。

Should I use a ListView, or is there something better? 我应该使用ListView还是有更好的选择?

  1. You can make a Listview layout with single textview 您可以使用单个textview进行Listview布局
  2. Use Arraylist to hold basically 2 things i. 使用Arraylist基本上可以保存两件事。 The title of your Hyperlink ii. 超级链接的标题ii。 The Url it would redirect to 它将重定向到的网址
  3. Set a Adapter to your ListView Adapter设置为您的ListView
  4. Set a ClickListener to your ListView ClickListener设置到您的ListView
  5. When a Particular item is clicked you can the postion of your listView item to get content in a Arraylist 单击特定项目时,您可以将listView项目的位置获取到Arraylist中的内容

eg. 例如。

  arraylist.get(postion).name
  arraylist.get(postion).url

Now you can just start a WebView using Intents 现在,您可以使用Intents启动WebView

Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(browserIntent);

Also if you have too many items to be displayed, I would recommend using RecyclerView 另外,如果要显示的项目太多,我建议使用RecyclerView

我建议您使用RecyclerView ,因此在每个包含TextView属性为android:autoLink="web"结果项目视图中,也请查看android:linksClickable属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM