在列表视图项中动态插入textView

时间:2012-09-18 16:43:33

标签: android listview

在我的应用程序中,我想动态地在自定义textview适配器行中插入listview。想要添加一些行而不想插入一些行。此文本视图将为none或其数量取决于我的适配器值。 但我怎么能这样做。我没有想法..

这是我的Listview适配器的代码

package com.app.sample;

import java.util.ArrayList;

import com.app.sample.bl.TripInfo;
import com.app.sample.utilities.sampleLogging;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class TripListItemsAdapter extends ArrayAdapter<TripInfo> {

    private static ArrayList<TripInfo> itemDetailsrrayList;
    private LayoutInflater inflater;
    Context context;
    int layoutResourceId;
    String TripAdapterTag = "TAG";


    public TripListItemsAdapter(Context context, int viewResourceId,
            ArrayList<TripInfo> results) {
        super(context, viewResourceId, results);
        this.layoutResourceId = viewResourceId;
        this.context = context;
        itemDetailsrrayList = results;
        inflater = LayoutInflater.from(context);

    }

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

        View row = convertView;
        ViewHolder holder = null;
        try {
            if (row == null) {
                row = inflater.inflate(layoutResourceId, parent, false);

                holder = new ViewHolder();
                holder.icon = (ImageView) row.findViewById(R.id.iconImage);
                holder.tvTripNumber = (TextView) row
                        .findViewById(R.id.tvTripNumber);
                holder.tvPickupTime = (TextView) row
                        .findViewById(R.id.tvPickupTime);
                holder.tvNumberPersons = (TextView) row
                        .findViewById(R.id.tvNumberPersons);
                holder.tvIndexNumber = (TextView) row
                        .findViewById(R.id.tvIndexNumber);
                holder.tripState = (ImageView) row
                        .findViewById(R.id.iconTripState);

                row.setTag(holder);

            }

            holder = (ViewHolder) row.getTag();

            holder.tvPickupTime
                    .setText(itemDetailsrrayList.get(position).mPickupAdd);

            holder.tvNumberPersons.setText(String.valueOf(itemDetailsrrayList
                    .get(position).mNumPerson));
            holder.tvTripNumber.setText(String.valueOf(itemDetailsrrayList
                    .get(position).mTripNumber));

            holder.icon.setImageResource(R.drawable.ic_launcher);

            holder.tvIndexNumber.setText(String.valueOf(position + 1));

            switch (itemDetailsrrayList.get(position).mTripState) {

            case NOSHOW:
                holder.tripState.setImageResource(R.drawable.noshow);
                break;

            case EXECUTED:
                holder.tripState.setImageResource(R.drawable.correct);
                break;

            case SCHEDULED:
                holder.tripState.setImageResource(R.drawable.scheduled);
                break;

            case STARTED:
                holder.tripState.setImageResource(R.drawable.start);
                break;

            }

        } catch (Exception e) {
            sampleLogging.e("Exception :", e);
        }
        return row;
    }

    static class ViewHolder {
        TextView tvTripNumber;
        TextView tvPickupTime;
        TextView tvNumberPersons;
        TextView tvIndexNumber;
        ImageView icon;
        ImageView tripState;
    }
}

请任何机构建议我怎么办?请给我一些教程或示例。

由于

0 个答案:

没有答案