【问题标题】:Another Linkify question另一个 Linkify 问题
【发布时间】:2011-06-22 13:55:44
【问题描述】:

因为我是 android 编程新手,所以我不知道如何获取列表视图的链接。

我的链接代码是:

TextView textviewlink = new TextView(this);
textviewlink.setText("text I want to see"); 

TransformFilter mentionFilter = new TransformFilter() { 
public final String transformUrl(final Matcher match, String url) { 
return new String("http://test.com/"); 
} 
}; 

Pattern pattern = Pattern.compile("."); 
String scheme = ""; 
Linkify.addLinks(textviewlink, pattern, scheme, null, mentionFilter); 

Now I want to place textviewlink into a HashMap:

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); 
HashMap<String, String> map = new HashMap<String, String>();

所以我这样添加:

map.put("c1", "STATUTE");
map.put("c0", " ");
map.put("c2", textviewlink.toString()); 
mylist.add(map); 

然后:

ListView listnew = (ListView) findViewById(R.id.lvdata);
SimpleAdapter mSchedulenew = new SimpleAdapter(this, (List<? extends Map<String, ?>>) mylist, R.layout.row, 
new String[] {"c1","c0","c2"}, new int[] {R.id.CELL1,R.id.CELLBlank, R.id.CELL2}); 
listnew.setAdapter(mSchedulenew);   

但是当我显示它时,链接看起来像:

android.widget.textview@43e604c0

【问题讨论】:

    标签: android listview linkify


    【解决方案1】:

    您想使用textviewlink.getText() 而不是textviewlink.toString()

    toString() 只是返回对象的字符串表示形式,这与其文本值不同。

    【讨论】:

    • ArrayList> mylist = new ArrayList>(); HashMap map = new HashMap();
    • 然后我得到了“我想看的文字”,但它没有产生链接。
    猜你喜欢
    • 1970-01-01
    • 2011-05-05
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多