两个阵列在一个TextView中在ListView [英] Two arrays in one TextView in a ListView

查看:155
本文介绍了两个阵列在一个TextView中在ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我很想得到答案的问题。

I have a question that I would love to get an answer on.

我有两个数组,让我们说:

I have two arrays, let's say:

String[] name = {"Name Nameson", "Second Name"};
String[] number = {"111 11 111", "222 22 222"};

我希望我的ListView有两个TextViews成一个项目。(我试图说明这一点用图片)。

I want my ListView to have two TextViews into one item.(I tried to illustrate this with a picture).

我设法让f.ex.我的名字数组列表视图用一个简单的

I manage to get f.ex. my name array into the listview with a simple

lv.setAdapter(new ArrayAdapter<String>(this, R.layout.single_name, name));

我有我与我的吧,single_name.xml和single_number.xml在我的布局文件夹的ListView main.xml中。

I have my main.xml with my ListView in it, single_name.xml and single_number.xml in my layout-folder.

由于我是新来这个网站,我不允许添加图片​​,我会尝试在这里介绍它:

Since I'm new to this site I'm not allowed to add a picture, I will try to illustrate it here:

标题

(项目的)

南旋名

111 11 111

111 11 111

(项目二)

第二个名字

222 22 222

222 22 222

和这种情况持续下去取决于接触的数量。

And this continues depending on quantity of contacts.

任何帮助将大大AP preciated:)

Any help would be greatly appreciated :)

在此先感谢!

推荐答案

您将需要建立一个自定义适配器以及自定义视图重新present每排在列表中。

You will need to build a custom Adapter as well a custom view to represent each row in your List.

下面是一个简单的适配器与2 textviews和ImageView的一个列表视图的一个例子。修改你认为合适的,包括你的头,并采取了ImageView的

Here's an example of a simple adapter for a listview with 2 textviews and an imageview. Modify as you see fit to include your header and take out the imageview

package com.aquarius.customlistviewproject;


public class CustomListViewAdapter extends BaseAdapter{


 private ArrayList<String> album_names;

private ArrayList<String> num_photos;

 public Activity context;

public LayoutInflater inflater;

 public CustomListViewAdapter(Activity context, ArrayList<String> album_names ,     ArrayList<String> num_photos){

super();
this.album_names = album_names;
this.num_photos = num_photos;
this.context = context;
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}


public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

public int getCount() {
    // TODO Auto-generated method stub
    return album_names.size();
}

public class ViewHolder{

    ImageView thumbnail;
    TextView  title;
    TextView photos;
}

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

    ViewHolder holder;

    if(convertView == null){
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.listview_row, null);

        holder.thumbnail = (ImageView)convertView.findViewById(R.id.imgViewLogo);
        holder.title = (TextView)convertView.findViewById(R.id.txtViewTitle);
        holder.photos = (TextView)convertView.findViewById(R.id.txtViewDescription);


        convertView.setTag(holder);
    }

    else
        holder = (ViewHolder)convertView.getTag();
        holder.thumbnail.setImageResource(R.drawable.imgview_drawable);

        holder.title.setText(album_names.get(position));
        holder.photos.setText(num_photos.get(position));
    return convertView;
}

}

这篇关于两个阵列在一个TextView中在ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆