Android 如何将textview用作html页面?
因此,我有一个包含这些代码的Asynctask类,我只想将内容的视图从文本更改为htmlAndroid 如何将textview用作html页面?,android,android-asynctask,textview,Android,Android Asynctask,Textview,因此,我有一个包含这些代码的Asynctask类,我只想将内容的视图从文本更改为html private class JSONP extends AsyncTask<String, String, JSONObject>{ @Override protected void onPreExecute() { super.onPreExecute(); title=(TextView)findViewById(R.id.tex
private class JSONP extends AsyncTask<String, String, JSONObject>{
@Override
protected void onPreExecute() {
super.onPreExecute();
title=(TextView)findViewById(R.id.textView2);
content=(TextView)findViewById(R.id.txtcontent);
}
@Override
protected JSONObject doInBackground(String... arg0) {
JSONParser jp = new JSONParser();
JSONObject tempjo = jp.getjsonfromurl(url);
return tempjo;
}
@Override
protected void onPostExecute(JSONObject result) {
super.onPostExecute(result);
try {
news = result.getJSONArray(Tag_posts);
for(int i = 0;i<news.length();i++){
JSONObject c = news.getJSONObject(i);
String titles = c.getString(Tag_title);
String contents = c.getString(Tag_content);
HashMap<String, String> map = new HashMap<String, String>();
map.put(Tag_title, titles);
map.put(Tag_content, contents);
newslist.add(map);
ListAdapter list = new SimpleAdapter(MainActivity.this,
newslist,
R.layout.listv,
new String[] {Tag_title,Tag_content},
new int[]{R.id.textView2, R.id.txtcontent});
mylist.setAdapter(list);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
但我不知道该把代码放在哪里?创建另一个类或直接在我的asynctask类中使用它html变量在哪里?如果您谈论的是显示json,那么可以在将adapterits设置为字符串后立即进行显示。我已经用这个代码得到了它:String contents=c.getStringTag\u content;因此,只需将您的textview.setText放在onPostExecute方法中;无法在列表适配器中执行此操作。为此,您必须创建自定义适配器,在自定义适配器的getView方法中,您可以实现它
textView.setText(Html.fromHtml(contents));