Listview包含来自Html字符串和图像问题的文本集

时间:2013-07-04 09:22:12

标签: android html android-listview

我有自定义列表视图,包含文本和图像,每行文本都是从string.xml中的html字符串中检索的,

因此每行必须显示文本和图像,但是当我运行应用程序时它不显示html标记,它获取存储在string.xml中的文本并在每行中显示但没有html标记效果,还有每行中没有显示的图像

我们如何才能最终显示列表行包含带有html标签和图像的文本。

任何建议都将受到高度赞赏。

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
     ListView listView = (ListView)findViewById(R.id.lis);
     String[] textEntries = {getString(R.string.day1),getString(R.string.day2), 
                             getString(R.string.day3),getString(R.string.day4),
                             getString(R.string.day5)};

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, textEntries);
 listView.setAdapter(adapter);
    }
}

适配器类

public class MyAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] textEntries;
Typeface tf;
static class ViewHolder {
    public TextView text;
    public ImageView image;
    }     
public MyAdapter(Activity context, String[] textEntries) {
    super(context, R.layout.row, textEntries);
    this.context = context;
    this.textEntries = textEntries;
    tf=Typeface.createFromAsset(context.getAssets(),"BFantezy.ttf");
    }                                                   
@Override
public View getView(int position, View convertView, ViewGroup parent) {     
    View rowView = convertView;
    if (rowView == null) {
      LayoutInflater inflater = context.getLayoutInflater();
      rowView = inflater.inflate(R.layout.row, null);
      ViewHolder viewHolder = new ViewHolder();
      viewHolder.text = (TextView) rowView.findViewById(R.id.row_label);
      viewHolder.image = (ImageView) rowView.findViewById(R.id.row_image);
      viewHolder.text.setTypeface(FontFactory.getBFantezy(getContext()));
      rowView.setTag(viewHolder);
      }     
     ViewHolder holder = (ViewHolder) rowView.getTag();
     String s = textEntries[position];
     holder.text.setText(s);

if ( s.startsWith("day1")) {
    holder.image.setImageResource(R.drawable.a); 
    }                       
if ( s.startsWith("day2")) {
    holder.image.setImageResource(R.drawable.b); 
    }       
if ( s.startsWith("day3")) {
    holder.image.setImageResource(R.drawable.c); 
    }                       
if ( s.startsWith("day4")) {
    holder.image.setImageResource(R.drawable.d); 
    }       
if ( s.startsWith("day5")) {
    holder.image.setImageResource(R.drawable.e); 
    }                       
return rowView;  
}
}

0 个答案:

没有答案