在我的应用程序中,我想动态插入textview
自定义listview
适配器行。想要添加一些行并且不想插入一些行。这个文本视图将是无或它的数量取决于我的适配器值。但我该怎么做。我不知道..
这是我的 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;
}
}
请任何人建议我该怎么做请给我一些教程或示例。
谢谢