我正在使用Linkify(文本,模式,方案)来识别对话框中显示的文本中的正则表达式。我想通过链接引导用户访问我程序的其他部分。
一些背景知识:
我的应用是一个字典风格的应用。 ListView的术语被散列为定义列表。当用户点击一个术语时,该定义会在AlertDialog中弹出。其中一些定义本身实际上包含其他术语。例如:
term: "dog"
definition: "A mid-sized furry domesticated animal. Not to be confused with [cat]s."
在上述情况下,用户可以单击“cat”一词,这会导致对话框关闭,并且在其位置应显示“cat”的定义。
问题是,Linkify()的唯一文档涉及打开Web URL。我需要链接来向程序表明它需要转到另一个定义。
目前,我称这样的定义为:
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() { // when an item is clicked on...
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Linkify parameters
Pattern pattern = Pattern.compile("\\[[^]]*]"); // defines the fact that links are bound by [square brackets]
String scheme = ""; // *** THIS IS WHERE I NEED TO ADD A PROPER SCHEME ***
AlertDialog alertDialog = new AlertDialog.Builder(ListProjectActivity.this).create(); // create a dialog box in memory
alertDialog.setTitle(((TextView) view).getText()); // set title of dialog box to term name
SpannableString definition = new SpannableString(dictionaryMap.get(((TextView) view).getText())); // grab the definition by checking against the dictionary map hash
Linkify.addLinks(definition, pattern, scheme); // add links to definition
alertDialog.setMessage(definition); // set dialog box message to term definition
alertDialog.show(); // actually display the dialog box
}
如何让Linkify()链接调用另一个AlertDialog?