在列表視圖中滾動幾秒鐘後,應用程序崩潰。帶有兩種不同佈局的列表視圖
String[] names = new String[] {"Cook","2/Person/15/5","Cashier","2/Person/15/5"};
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View rowView = convertView;
LayoutInflater inflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String[] info = names.get(position).split("/");
if (rowView == null) {
if (info.length != 1) {
rowView = inflater.inflate(R.layout.employee, null, true);
holder = new ViewHolder();
holder.name = (TextView) rowView.findViewById(R.id.name);
holder.money= (TextView) rowView.findViewById(R.id.money);
holder.rating = (RatingBar) rowView.findViewById(R.id.rating);
rowView.setTag(holder);
}else{
rowView = inflater.inflate(R.layout.lable, null, true);
holder = new ViewHolder();
holder.lable = (TextView) rowView.findViewById(R.id.name);
rowView.setTag(holder);
}
}
holder = (ViewHolder) rowView.getTag();
if (holder.lable==null) {
holder.name.setText(info[1]);
holder.money.setText(info[2]);
holder.rating.setRating(Float.valueOf("1"));
}else{
holder.lable.setText(names.get(position));
}
//}
return rowView;
}
發佈您的錯誤日誌。 – kcoppock 2011-05-26 21:34:06
使用Logcat查看確切的錯誤消息:'adb logcat'或者日食中的DDMS透視圖 – 2011-05-26 21:35:32
它表示爲nullPointerexeption @ holder.lable.setText(names.get(position)); – Michael 2011-05-26 22:01:44