如何在基本适配器中使用进度对话框
how to use progress dialog in base adapter
我有一个带有一些文本视图和一个按钮的自定义列表视图。单击按钮我想将列表视图值保存到服务器,为了完成此任务我正在使用 asyntask 但我的代码在 pregress 对话框中崩溃了。我在如何通过 activity 的实例以使用进度对话框
时遇到问题
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;
}
可能 context
是 null
。使用您在 SaveDCR
class 构造函数中传递的 mContext
来创建进度条:
@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);
我有一个带有一些文本视图和一个按钮的自定义列表视图。单击按钮我想将列表视图值保存到服务器,为了完成此任务我正在使用 asyntask 但我的代码在 pregress 对话框中崩溃了。我在如何通过 activity 的实例以使用进度对话框
时遇到问题 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;
}
可能 context
是 null
。使用您在 SaveDCR
class 构造函数中传递的 mContext
来创建进度条:
@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);