我有一個自定義列表視圖與一個按鈕來添加更多元素 但當我添加和元素的應用程序崩潰,但是當我重新啓動時,我發現該元素添加,(很少它不會崩潰)列表視圖滾動時滯後,並添加項目時崩潰
而且我
我使用自定義適配器
class CustomAdapter extends BaseAdapter {
ArrayList<ListItem> listItems = new ArrayList<ListItem>();
CustomAdapter(ArrayList<ListItem> list){
this.listItems = list;
}
@Override
public int getCount() {
return listItems.size();
}
@Override
public Object getItem(int position) {
return listItems.get(position).name;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int i, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.list_item,null);
TextView name = (TextView) view.findViewById(R.id.name);
TextView lastm = (TextView) view.findViewById(R.id.last);
TextView time = (TextView) view.findViewById(R.id.time);
CircleImageView pic= (CircleImageView) view.findViewById(R.id.pic);
name.setText(listItems.get(i).name);
lastm.setText(listItems.get(i).lastm);
time.setText(listItems.get(i).time);
Bitmap bmp = BitmapFactory.decodeByteArray(listItems.get(i).pic,0,listItems.get(i).pic.length);
pic.setImageBitmap(bmp);
return view;
}
}
,當我添加元素的應用crashs
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText editText=(EditText) mView.findViewById(R.id.name);
String name=editText.getText().toString();
boolean result=myDataBase.insertData(imageViewToByte(img),name,"no messages yet","");
if (result) {
Toast.makeText(Main2Activity.this, "Saved in DATABASE", Toast.LENGTH_SHORT).show();
viewLastData();
dialog.dismiss();
}
「崩潰」 ..;你有這樣的崩潰堆棧跟蹤? – Stultuske
你可以添加你的xml代碼嗎? –
Stulktuske我不明白,「堆棧跟蹤?」 –