我有一个带有锚点的html字符串的textview。当我点击textview时,我想调用一个名为A的方法,当我在textview中单击一个链接时,我想调用一个名为B的方法。我得到了这个工作,但我遇到了一个问题:当我单击一个链接时,方法B被调用,但方法A也被调用。我怎样才能确保只有方法B,而不是B和A,当我点击链接时被调用?带有链接的Textview onclicklistener
我的代码:
for (int i = 0; i < ingevoegd.length(); i++) {
JSONObject soortingevoegd = ingevoegd.getJSONObject(i);
String type = soortingevoegd.getString("type");
if (type.equals("Vis")) {
String link = "<a href = 'com.aquariumzoeken.pro://Soortweergave?selected="
+ naam + "&type=Vis" + "'>" + naam + "</a>";
text = text.replaceAll(naam, link);
}
}
TextView texttv = (TextView) v.findViewById(R.id.textviewer);
texttv.setText(Html.fromHtml(text));
texttv.setMovementMethod(LinkMovementMethod.getInstance());
而且TextView的onclicklistener:
texttv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
switchToEditMode sw = new switchToEditMode();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
由于提前, 西蒙
您是否尝试过让'机器人:自动链接= “网络” 为'TextView的和不附加LinkMovement?我认为这应该工作。 – Slartibartfast
不幸的是,这不起作用。我的链接不能以这种方式点击。 – Simon
你可以附上一张截图吗,我发现很难想象布局以及为什么附加两个事件,电视中其他地方是否有空白空间,以及那些你需要的方法B? – Slartibartfast