我正在尝试创建一个使用以下代码平滑滚动的列表视图:
<ListView
android:id="@+id/list2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:listSelector="@android:color/transparent" />
// tt 是包含 100 个对象的 x (Object) 数组。
x[] tt= response.getX();
ItemsAdapter myListAdapter = new ItemsAdapter(getActivity(),R.layout.mylist, tt);
// setListAdapter(myListAdapter);
list2.setAdapter(myListAdapter);
// 适配器列表视图
public class ItemsAdapter extends BaseAdapter {
Context myContext;
private int customLayoutId = -1;
private X[] items;
public ItemsAdapter(Context context, int resource, X[] x) {
customLayoutId = resource;
myContext = context;
this.items = x;
}
public View getView(final int position, View convertView,
ViewGroup parent) {
// View row = convertView;
try {
LayoutInflater inflator = ((Activity) myContext)
.getLayoutInflater();
xdata= items[position];
if (convertView == null) {
// row = inflater.inflate(customLayoutId, null);
convertView = inflator.inflate(customLayoutId, null);
DataViewHolder viewHolder1 = null;
viewHolder1 = new DataViewHolder();
viewHolder1.numberTV = (TextView) convertView
.findViewById(R.id.numberTV);
viewHolder1.costTV = (TextView) convertView
.findViewById(R.id.costTV);
viewHolder1.reserveButton = (Button) convertView
.findViewById(R.id.reserveButton);
viewHolder1.reserveButton
.setBackgroundResource(R.drawable.reserve_button);
viewHolder1.position = position;
convertView.setTag(viewHolder1);
}
DataViewHolder viewHolder1 = (DataViewHolder) convertView
.getTag();
viewHolder1.numberTV.setText(xdata.getMsisdn());
viewHolder1.costTV.setText(etrData.getPrice());
viewHolder1.reserveButton
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
});
} catch (Exception e) {
e.printStackTrace();
}
return convertView;
}
}
@Override
public int getCount() {
return this.items.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
}
static class DataViewHolder {
public TextView numberTV;
public TextView costTV;
public Button reserveButton;
public int position;
}
当我滚动此列表时,应用程序崩溃是 Logcat 中的内容:
07-27 02:50:26.756: I/Choreographer(24450): Skipped 46 frames! The application may be doing too much work on its main thread.
07-27 02:50:27.497: I/Choreographer(24450): Skipped 41 frames! The application may be doing too much work on its main thread.
07-27 02:50:28.698: I/Choreographer(24450): Skipped 32 frames! The application may be doing too much work on its main thread.
07-27 02:50:34.724: D/dalvikvm(24450): GC_CONCURRENT freed 1120K, 12% free 13993K/15815K, paused 6ms+6ms, total 35ms
07-27 02:50:35.655: I/Choreographer(24450): Skipped 41 frames! The application may be doing too much work on its main thread.
07-27 02:50:45.685: I/Choreographer(24450): Skipped 58 frames! The application may be doing too much work on its main thread.
07-27 02:50:46.936: I/Choreographer(24450): Skipped 69 frames! The application may be doing too much work on its main thread.
07-27 02:50:57.677: I/Choreographer(24450): Skipped 31 frames! The application may be doing too much work on its main thread.
07-27 02:50:59.639: I/Choreographer(24450): Skipped 53 frames! The application may be doing too much work on its main thread.
07-27 02:51:03.953: D/TextLayoutCache(24450): Cache value 0x54a260f0 deleted, size = 280
07-27 02:51:03.963: D/TextLayoutCache(24450): Cache value 0x41002fd0 deleted, size = 400
07-27 02:51:03.963: D/TextLayoutCache(24450): Cache value 0x40f05908 deleted, size = 360
07-27 02:51:04.113: D/TextLayoutCache(24450): Cache value 0x413aa480 deleted, size = 384
07-27 02:51:04.123: D/TextLayoutCache(24450): Cache value 0x413a6200 deleted, size = 408
这些错误应该如何处理?我究竟做错了什么?