如何访问ArrayList数据到ListView,在Android中有多个textview和图像图标?

时间:2012-03-08 10:23:55

标签: android listview arraylist android-listview listadapter

我创建了一个ArrayList,其中包含服务器响应的数据。现在Arraylist拥有我所提供的所有数据。但我想将这些数据显示在列表视图中。

例如:['videoName','VideoCategory','缩略图路径']

这是arraylist:

mydata=['a1','science','/playback/2012/09_im.jpg','a2','maths','/playback/2012/01.jpg'.....]

现在我想在textView1中显示'videoName',在textView2中显示'VideoCategory',在图像图标中显示'缩略图路径'。

我正在尝试ArrayList Adapter。但是有几个问题发生了。

请帮助我......

1 个答案:

答案 0 :(得分:0)

您必须使用自定义ListView,并且必须使用BaseAdapter。这是自定义ListView示例的链接:

http://android-codes-examples.blogspot.in/2011/03/multiple-listview-and-custom-listview.html

set   list.setAdapter(new EfficientAdapter(getApplicationContext()));
    public  class EfficientAdapter extends BaseAdapter  {


            ViewHolder holder; 
            private LayoutInflater mInflater;
            Activity context = null;

            public static final int DIALOG_DOWNLOAD_PROGRESS = 0;












            public EfficientAdapter(Context context) {
                mInflater = LayoutInflater.from(context);


            }


            public int getCount() {
                return one.size();
            }

            public Object getItem(int position) {
                return position;
            }

            public long getItemId(int position) {
                return 0;
            }

            public View getView(final int position, View convertView, ViewGroup parent) {

                if (convertView == null) {
                    convertView = mInflater.inflate(R.layout.listitem, null);



                    holder = new ViewHolder();
                    holder.text = (TextView) convertView.findViewById(R.id.TextView01);
                    holder.text1 = (TextView) convertView.findViewById(R.id.TextView02);
                    holder.image = (ImageView) convertView.findViewById(R.id.ImageView01);
                    holder.btn = (Button) convertView.findViewById(R.id.B);
                    holder.btn.setFocusable(false);

                    convertView.setTag(holder);

                } else {
                    holder = (ViewHolder) convertView.getTag();
                }







                holder.text.setText(one.get(position));
                holder.text1.setText("Stall No: "+two.get(position));







                return convertView;

            }



            class ViewHolder {
                TextView text;
                TextView text1;
                ImageView image;
                Button btn;


            }

现在使用您想要的ListView