android - android中如何以表格形式显示ListView

标签 android listview

我想以表格格式显示一个 ListView

ListView 应该像 Excel 工作表一样有行和列。

谁能建议如何实现这个?

最佳答案

    class CustomAdapterCoupons extends BaseAdapter {
    /* Variable Declaration */
    private Context context;

    private List<CouponBean> list;

    private CouponBean entry;
    public com.pocketJini.util.ImageLoader imageLoader;
    private LayoutInflater inflater;

    public CustomAdapterCoupons(Context context, List<CouponBean> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) CouponsActivity.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader = new com.pocketJini.util.ImageLoader(context);
    }

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

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

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

    public class ViewHolder {
        public TextView couponName, couponCode, usageDescription,
                expirationDate;
        public ImageView couponImage;

    }

    public View getView(final int position, View convertView,
            ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;

        entry = list.get(position);

        if (convertView == null) {

            convertView = inflater.inflate(R.layout.coupons_list_layout,
                    null);

            holder = new ViewHolder();

            holder.couponName = (TextView) convertView
                    .findViewById(R.id.CouponListCouponName);
            holder.couponCode = (TextView) convertView
                    .findViewById(R.id.CouponListCouponCode);
            holder.expirationDate = (TextView) convertView
                    .findViewById(R.id.CouponListDetailDate);
            holder.usageDescription = (TextView) convertView
                    .findViewById(R.id.CouponListUsageDescription);
            holder.couponImage = (ImageView) convertView
                    .findViewById(R.id.CouponListLeftImage);

            convertView.setTag(holder);
            // Set the display text
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.couponName.setText(entry.getCouponName());
        holder.expirationDate.setText(context
                .getString(R.string.Coupon_Expiration_Date)
                + "\n"
                + entry.getExpirationDate());
        holder.usageDescription.setText(entry.getUsageDescription());
        holder.couponCode.setText(entry.getCouponCode());

        holder.couponImage.setTag(Data.URL_BASE_2 + entry.getCouponImage());
        imageLoader.DisplayImage(Data.URL_BASE_2 + entry.getCouponImage(),
                (Activity) context, holder.couponImage);
        Log.v(Data.LOG3, "image" + entry.getCouponImage());

        final Button savedMyCoupons = (Button) convertView
                .findViewById(R.id.CouponListAddtoMyCouponButton);
        if (entry.getSavedMyCoupons().equalsIgnoreCase("N")) {
            savedMyCoupons.setText(context
                    .getString(R.string.Add_to_myCoupons));
            savedMyCoupons.setBackgroundResource(R.drawable.done_btn);
            savedMyCoupons.setTag(entry.getCouponId().toString());
            savedMyCoupons.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    createProgressDialog();

                    new Loader()
                            .execute(savedMyCoupons.getTag().toString());
                }
            });

        } else if (entry.getSavedMyCoupons().equalsIgnoreCase("Y")) {
            savedMyCoupons.setText(context
                    .getString(R.string.Already_Added_to_my_coupons));
            savedMyCoupons.setBackgroundColor(Color.WHITE);
            savedMyCoupons.setTextColor(Color.BLACK);

        }

        // display the view corresponding to data at specified position
        return convertView;

    }
}

关于android - android中如何以表格形式显示ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9904313/

相关文章:

android - 在抽屉导航中突出显示所选项目

java - 使用带有 View 而不是 Activity 的 Android 选项卡的示例?

android - 发布应用程序的内容存储

java - 在 Asynctask 中显示 Progresscircle

java - 将数组列表用于状态机

listview - 如何为选定的 ListItem onTap 着色

android - 拉动以刷新android中的水平 ListView

android - 从 ListView 和 ArrayAdapter 中删除项目

css - Kendo MVC ListView 小部件无限滚动不起作用

android - 自定义 ListView setOnItemClickListener