【发布时间】:2015-06-13 06:47:31
【问题描述】:
我有一个 textview,其中包含一个亚马逊 URL。我可以使用完整的 URL 来完成这项工作,它会在浏览器中打开链接。
但是,我不想在 textview 中显示整个 URL,我想将其替换为文本“购买”。我希望将所有链接的 textview 设置为 BUY。
我看到了每个文本视图和 URL 都是单独固定的问题。但一般来说并不是所有人。我试过这个 - http://jtomlinson.blogspot.co.uk/2010/03/textview-and-html.html - 我设法将文本设置为“购买”,但它不再是一个可点击的链接。
只是为了提供更多信息。在我的应用程序中,我将 xml 解析到数据库中,搜索将在包含文本视图的列表视图中返回结果。
这是我的 onclicklistener 代码:
myList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Get the cursor, positioned to the corresponding row in the result set
Cursor cursor = (Cursor) myList.getItemAtPosition(position);
//fix this line. modify string value
// String searchValue = cursor.getString(cursor.getColumnIndexOrThrow("searchValue"));
String author = cursor.getString(cursor.getColumnIndexOrThrow("author"));
String title = cursor.getString(cursor.getColumnIndexOrThrow("title"));
String price = cursor.getString(cursor.getColumnIndexOrThrow("price"));
String publish_date = cursor.getString(cursor.getColumnIndexOrThrow("date"));
String description = cursor.getString(cursor.getColumnIndexOrThrow("description"));
String module = cursor.getString(cursor.getColumnIndexOrThrow("module"));
String buy = cursor.getString(cursor.getColumnIndexOrThrow("buy"));
//Check if the Layout already exists
LinearLayout bookLayout = (LinearLayout)findViewById(R.id.customerLayout);
if(bookLayout == null){
//Inflate the Customer Information Vie
LinearLayout xbookLayout = (LinearLayout)findViewById(R.id.Layout);
View book = getLayoutInflater().inflate(R.layout.book_info, xbookLayout, false);
xbookLayout.addView(book);
}
//Get References to the TextViews
authorText = (TextView) findViewById(R.id.xauthor);
titleText = (TextView) findViewById(R.id.xtitle);
priceText = (TextView) findViewById(R.id.xprice);
publishDateText = (TextView) findViewById(R.id.xpublish_date);
descriptionText = (TextView) findViewById(R.id.xdescription);
moduleText = (TextView) findViewById(R.id.xmodule);
buyText = (TextView) findViewById(R.id.xbuy);
// Update the parent class's TextView
authorText.setText(author);
titleText.setText(title);
priceText.setText(price);
publishDateText.setText(publish_date);
descriptionText.setText(description);
moduleText.setText(module);
buyText.setText(buy);
searchView.setQuery("",true);
【问题讨论】:
-
如果你有项目在列表中的位置(在 OnItemClick 中)然后只需调用一个光标和 getString 再次“购买”......就像你在 getView 中所做的那样。最好叫它“url”。
-
然后呢?不可能,目前我的链接可以通过xml中的这段代码点击 android:clickable="true" android:autoLink="all"/>
-
您不需要链接。如果您在列表视图上设置了项目点击侦听器,则您的文本视图是可点击的。因此,如果单击该项目,则提取相应的 url 并移交给浏览器。
-
对不起,我只是不明白你想说什么。我可以点击链接并正常工作。但这仅来自存储在我的数据库中的纯 URL。我想用文本“购买”替换将放置在 buyText 文本视图中的每个 URL。
-
您可以在您想要的每个文本视图中放置“购买”。该文本无关紧要。在点击处理程序中,您可以获得位置,并且可以获得该位置的 url。然后启动浏览器。我没有看到你的问题。
标签: android html url hyperlink textview