ListAdapter中的多个ArrayLists [Android]

时间:2015-07-29 10:56:13

标签: android listview

在Niv的回答之后

更新代码

这是适配器方法:

public class PostsListAdapter extends ArrayAdapter<String> {

/**
 * ViewHolder class for layout.<br />
 * <br />
 */
private static class ViewHolder {
    public final RelativeLayout rootView;
    public final TextView postUname;
    public final TextView postText;
    public final ImageView postPlatform;
    public final ImageView postImage;
    public final VideoView postVideo;

    private ViewHolder(RelativeLayout rootView, TextView postUname, TextView postText, ImageView postPlatform, ImageView postImage, VideoView postVideo) {
        this.rootView = rootView;
        this.postUname = postUname;
        this.postText = postText;
        this.postPlatform = postPlatform;
        this.postImage = postImage;
        this.postVideo = postVideo;
    }

    public static ViewHolder create(RelativeLayout rootView) {
        TextView postUname = (TextView)rootView.findViewById( R.id.post_uname );
        TextView postText = (TextView)rootView.findViewById( R.id.post_text );
        ImageView postPlatform = (ImageView)rootView.findViewById( R.id.post_platform );
        ImageView postImage = (ImageView)rootView.findViewById( R.id.post_image );
        VideoView postVideo = (VideoView)rootView.findViewById( R.id.post_video );
        return new ViewHolder( rootView, postUname, postText, postPlatform, postImage, postVideo );
    }
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if ( convertView == null ) {
        View view = mInflater.inflate( R.layout.post_list, parent, false );
        vh = ViewHolder.create( (RelativeLayout)view );
        view.setTag( vh );
    } else {
        vh = (ViewHolder)convertView.getTag();
    }

    Object item = getItem( position );

    Log.d("Text", item.toString());
    vh.postText.setText(item.toString());

    return vh.rootView;
}

private LayoutInflater mInflater;

// Constructors
public PostsListAdapter(Context context, ArrayList<String> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from( context );
}

}

现在,问题是,如何传递多个arraylists,就像我有八个数组,我必须从中填充列表。 就像,对于每个项目,我必须得到八个项目来显示该项目,我将这八个arraylists排序以保持一对一的对应。

知道如何处理多个arraylists吗?

2 个答案:

答案 0 :(得分:1)

试用此代码。示例适配器

公共类ListAdapter扩展了ArrayAdapter {

def executorWithBoundedQueue(): ExecutorService = {
    val boundedQueue = new LinkedBlockingQueue[Runnable](1000)
    new ThreadPoolExecutor(boundedQueue)
}

}

答案 1 :(得分:0)

不完全理解你的问题,但你可以像这样传递List参数

List<List<String>> datalist = new Arraylist<>();

包含字符串列表的对象列表列表

希望,这会对你有所帮助