Android Open Source - RequestListView Array Adapter






From Project

Back to project page RequestListView.

License

The source code is released under:

Apache License

If you think the Android project RequestListView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright (c) 2013, Yoson Hao ???? (haoyuexing@gmail.com).
 *//  w  w w.j a v  a  2  s.  c o  m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hao.requestlistviewdemo;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ArrayAdapter extends BaseAdapter {

  ViewHolder mHolder;

  private Context mContext;
  private List<ArrayBean> mList = new ArrayList<ArrayBean>();

  public ArrayAdapter(List<ArrayBean> list, Context context) {
    super();
    this.mList = list;
    this.mContext = context;
  }

  @Override
  public int getCount() {
    return mList.size();
  }

  @Override
  public Object getItem(int arg0) {
    return mList.get(arg0);
  }

  @Override
  public long getItemId(int arg0) {
    return arg0;
  }

  @Override
  public View getView(int arg0, View arg1, ViewGroup arg2) {

    View view = arg1;

    if (view == null) {
      view = LayoutInflater.from(mContext).inflate(R.layout.item_array, null);
      mHolder = new ViewHolder();
      mHolder.name = (TextView) view.findViewById(R.id.name);
      mHolder.email = (TextView) view.findViewById(R.id.email);
      view.setTag(mHolder);
    } else {
      mHolder = (ViewHolder) view.getTag();
    }

    ArrayBean arrayBean = mList.get(arg0);
    if (arrayBean != null) {
      mHolder.name.setText("Name:" + arrayBean.getName());
      mHolder.email.setText("Email:" + arrayBean.getEmail());
    }
    return view;
  }

  static class ViewHolder {
    TextView name, email;
  }

}




Java Source Code List

com.hao.requestlistview.RequestListView.java
com.hao.requestlistviewdemo.ArrayAdapter.java
com.hao.requestlistviewdemo.ArrayBean.java
com.hao.requestlistviewdemo.MainActivity.java