Android 我们可以在列表项中插入图像和文本视图吗

Android 我们可以在列表项中插入图像和文本视图吗,android,listview,Android,Listview,我正在进行一个项目,其中我有一个listview,我想在列表的每个项目中插入图像和文本。 我知道如何使列表项作出反应,但我不知道如何在listview项中添加图像或片段 为列表项创建自定义布局 创建自定义列表适配器 将ListAdapter设置为自定义适配器` public class CustomAdapter extends ArrayAdapter<String> { Context context; public CustomAdapter(Context contex

我正在进行一个项目,其中我有一个listview,我想在列表的每个项目中插入图像和文本。 我知道如何使列表项作出反应,但我不知道如何在listview项中添加图像或片段

  • 为列表项创建自定义布局
  • 创建自定义列表适配器
  • 将ListAdapter设置为自定义适配器`

     public class CustomAdapter extends ArrayAdapter<String> {
     Context context;
    
    public CustomAdapter(Context context) {
        super(context, android.R.layout.simple_list_item_1);
    
        this.context = context;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
       View view=convertView;
    
       if (convertView==null){view = vi.inflate(R.layout.listitem_birthday, parent,false);}
    
        TextView tv = (TextView) view.findViewById(R.id.textView);
    
     //set textview text
    
        ImageView iv = (ImageView) view.findViewById(R.id.imageView);
    
      //set image resource
    
    
        return view;
    }
    
    }
    

    是的,你可以。只要谷歌一下,我的意思是代码不是xml!是的,这两种方法都是可行的,你能举个例子吗?我想这是由视图持有者完成的,但我不知道如何实现,然后我将能够在listactivity中绑定adabter
       CustomAdapter adapter = new CustomAdapter(this);
            setListAdapter(adapter);