是的,使用自定义适配器,在其中你可以做任何你喜欢的事情;)这里有一些代码,但你也许应该看看其他例子来弄清楚适配器是如何工作的。
> public class Adapter_Custom extends BaseAdapter {
>
> // DEBUG
> private final String TAG = this.getClass().getSimpleName();
>
> // Layout
> private LayoutInflater inflater = null;
> public ViewHolder holder;
> View vi;
>
> Context context;
> private ArrayList<Item_Pin> pinItems;
>
> public Adapter_Custom(Context context, ArrayList<Item_Pin> pinItems) {
> this.context = context;
> this.pinItems = pinItems;
>
> inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
> }
>
> // Used internally by this class
> public int getCount() {
> return pinItems.size();
> }
>
> //
> @Override
> public long getItemId(int position) {
> // Return whatever u like here
> return 0;
> }
>
> @Override
> public String getItem(int position) {
> return "You can return whatever u like here";
> }
>
> public View getView(int position, View convertView, ViewGroup parent) {
>
> vi = convertView;
> // If there is no ViewHolder already, create a new one
> if(convertView == null){
> vi = inflater.inflate(R.layout.your_xml_file, null);
> holder = new ViewHolder();
>
> holder.title = (TextView)vi.findViewById(R.id.your_xml_file_textview);
> holder.background = (LinearLayout)vi.findViewById(R.id.your_xml_file_linearlayout);
>
> vi.setTag(holder);
> holder = (ViewHolder)vi.getTag(); // If there already is a viewholder, reuse it!
} else {
> holder = (ViewHolder)vi.getTag();
> }
> // This is where you place code for every list item - this is where you convert your base64 to images.
> holder.title.setText(pinItems.get(position).getPinText());
> // here you could also set the background of holder.background to your base64 image.
>
> return vi;
> }
>
> //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> // VIEWHOLDER - This is the code part of your XML
> //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> public class ViewHolder{
>
> public TextView title;
> public LinearLayout background;
>
> }
> }
使用该代码并将其替换为您自己的 XML 文件和数据,然后只需将代码放入 getView() 方法中,该方法将您的字节数组转换为每个列表项的图像。