我有自定义列表视图,其中包含一些textview和一个按钮。在按钮上单击我想将listview值保存到服务器,要执行此任务我正在使用asyntask但我的代码在pregress对话框中崩溃。我有问题如何传递活动的实例以使用进度对话框
public class ListViewAdapter extends BaseAdapter{
Context context;
public arrayList<Planning> arraylist;
private static LayoutInflater inflater = null;
public PlanningList_activity planActivity;
public ListView mListview;
Db_sqlite databaseHelper;
public ListViewAdapter(Context context,ArrayList<Plan> arraylist) {
this.context = context;
this.planArraylist = plan0Arraylist;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
databaseHelper = new Db_sqlite(context);
}
@Override
public int getCount() {
return planArraylist.size();
}
@Override
public Planning getItem(int arg0) {
return planArraylist.get(arg0);
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.single_lv_item, parent, false);
holder = new ViewHolder();
holder.tvdrCode = (TextView convertView.findViewById(R.id.Plan_no);
holder.tvDrName = (TextView) convertView.findViewById(R.id.doc_name);
holder.tvterrcode= (TextView) convertView.findViewById(R.id.mon);
holder.tvAdr = (TextView) convertView.findViewById(R.id.adr);
holder.tvClassDesc = (TextView) convertView.findViewById(R.id.class_desc);
holder.tvspeciality = (TextView) convertView.findViewById(R.id.ff_code);
holder.tvAreaName = (TextView) convertView.findViewById(R.id.area_name);
holder.tvShift = (TextView) convertView.findViewById(R.id.shift);
holder.btn_visited =(Button)convertView.findViewById(R.id.button1);
holder.btn_visited.setTag(position);
holder.btn_visited.setOnClickListener(ButtonClickListener);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
Planning p = planArraylist.get(position);
holder.tvdrCode.setText(p.getDocCode());
holder.tvDrName.setText(p.getDocName());
holder.tvterrcode.setText(p.getTerrCode());
holder.tvAdr.setText(p.getAdr());
holder.tvClassDesc.setText(p.getClassDesc());
holder.tvspeciality.setText(p.getSP());
holder.tvAreaName.setText(p.getAreaName());
holder.tvShift.setText(p.getMornEven());
return convertView;
}
static class ViewHolder {
TextView tvdrCode;
TextView tvDrName;
TextView tvterrcode;
TextView tvAdr;
TextView tvClassDesc;
TextView tvspeciality;
TextView tvAreaName;
TextView tvShift;
Button btn_visited;
}
答案 0 :(得分:0)
可能context
是null
。使用您在mContext
类构造函数中传递的SaveDCR
来创建进度条:
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(mContext);
progressDialog.setMessage("Saving...");
progressDialog.setCancelable(false);
progressDialog.show();
Log.e( "sending dvr to sqlite","yes");
}
从按钮点击传递上下文:
new SaveDCR(v.getContext()).execute(dvr);