0
嗨,我正在開發一個Android應用程序,我顯示評論相關的ticket.but在服務器端數據庫所有評論都存儲在HTML格式。當我發送請求它我得到的所有HTML code.But我設法通過我得到的HTML響應從服務器,但圖像標記不工作
comm.setText(Html.fromHtml(cmnt[position]));
轉換HTML代碼以正確的格式,但問題是,如果在評論圖像標籤,然後它會顯示小方塊代替的image.i想要忠實地展示那個形象。 請幫我
Single_Ticket.java
private class showcomment extends AsyncTask<String,String,String>
{
ProgressDialog pdialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
Log.v("TAG", "In onPreExecute of the loading comnt.");
}
protected String doInBackground(String... args) {
Log.v("TAG", "In doInBackground of the loading comment. ");
List<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("tktid", id));
ServiceHandler sh = new ServiceHandler();
String jsonStr = sh.makeServiceCall(URL_COMMENT, ServiceHandler.POST, param);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null)
{
try {
contacts = new JSONArray(jsonStr);
int a=contacts.length();
Log.v(TAG, ".................." + a);
if(a > 0) {
cmnt = new String[contacts.length()];
cmnt_time = new String[contacts.length()];
cmnt_by = new String[contacts.length()];
for (int i = (a-1),j=0; i >= 0&& j < contacts.length(); i--,j++) {
JSONObject c = contacts.getJSONObject(j);
Log.v(TAG, "" + i);
String aa = c.getString("cmnt");
String bb = c.getString("cmnt_time");
String cc = c.getString("cmnt_by");
Log.v(TAG,""+aa);
cmnt[i] = aa;
cmnt_time[i]=bb;
cmnt_by[i]=cc;
Log.v(TAG,""+cmnt[i]);
}
}
} catch (JSONException e) {
System.out.print("hiiiiiiiiiiii");
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(cmnt!=null && cmnt.length > 0) {
C_adapter adapter = new C_adapter(Single_Ticket.this, cmnt,cmnt_by,cmnt_time);
cmntview.setAdapter(adapter);
}
}
}
C_adapter.java
public class C_adapter extends ArrayAdapter {
Context context;
String[] cmnt;
String[] cmnt_by;
String[] cmnt_time;
LayoutInflater inflater;
public C_adapter(Single_Ticket context, String[] cmnt,String[] cmnt_by,String[] cmnt_time) {
super(context, R.id.cmnt_list,cmnt);
this.context=context;
this.cmnt=cmnt;
this.cmnt_by=cmnt_by;
this.cmnt_time=cmnt_time;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.cmnt_list, null);
}
TextView comm = (TextView) convertView.findViewById(R.id.cmnt);
TextView cmntby = (TextView) convertView.findViewById(R.id.cmntby);
comm.setText(Html.fromHtml(cmnt[position]));
if(cmnt_by[position].equalsIgnoreCase("Lalit Patil")|| cmnt_by[position].equalsIgnoreCase("Sarvesh Sonawane"))
{
//cmntby.setBackgroundResource(R.color.orange_red);
cmntby.setText(cmnt_time[position]+" - "+cmnt_by[position]);
}
cmntby.setText(cmnt_time[position]+" - "+cmnt_by[position]);
return convertView;
}
}
我從服務器響應這樣
{"cmnt":"<img src=\"http:\/\/i.imgur.com\/JHcdBVj.jpg\" width=\"448\"><br>","cmnt_time":"Wed,07 Oct 2015 05:41pm","cmnt_by":"test test"}
請幫助我.. –
圖片代碼不會TextView的工作。您應該使用WebView而不是TextView。 –