我有一個textview,其中包含一個亞馬遜網址。我可以使用完整的URL進行工作,並且會在瀏覽器中打開鏈接。如何爲所有textview網址創建一般標籤?
但是,我不希望整個URL在textview中,我想用文本'Buy'替換它。我希望將textview設置爲所有鏈接的購買。
我看到了每個文本視圖和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中一樣。最好稱之爲「網址」。 – greenapps
然後呢?那不可能是 也目前我的鏈接可以通過這個代碼在xml中點擊 android:clickable =「true」 android:autoLink =「all」/> – user3460355
你不需要鏈接。如果您已在列表視圖上設置了on on item click監聽器,則您的textview是可點擊的。因此,如果項目被點擊了extrackt根據url並交給瀏覽器。 – greenapps