'How to ckeck what tag does JSON API sends?
I am receiving text via JSON API inside my android application, but JSON sends this text in html form(like this: <a class="ps-media__link ps-media-link" href="https://www.example.com" rel="nofollow noopener" target="_blank">https://www.example.com</a>). What I want to do is to check what tag does the API send(e.g. p /p, a /a). I tried to achieve that with TagHandler but I can't. Here is my code:
public class TagHandler implements Html.TagHandler{
@Override
public void handleTag(boolean opening, String tag, Editable output,
XMLReader xmlReader) {
if(tag.equals("a")) {
Link = true;
}
}
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
PostsResponse post = postsResponseList.get(position);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
holder.postTxt.setText(Html.fromHtml(post.getPost(), Html.FROM_HTML_MODE_COMPACT));
if (Link == true) {
String Text = holder.postTxt.toString();
holder.postTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse(Text); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(intent);
}
});
}
} else {
holder.postTxt.setText(Html.fromHtml(post.getPost()));
}
How can I do that? Any answer will be appreciated!!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
