我有自定义对话框,显示列表,它正在工作,但是它需要花费太多时间才能打开,我也尝试使用DialogFragment解决它,但它显示的是,所以我该如何解决?请大家帮忙解决这个问题!
MyDialog.java
try {
switch (v.getId()) {
case R.id.ll_weight:
mDialogFor = 1;
if (mArrWeightList != null && mArrWeightList.size() > 0) {
Log.print("mIsDialogueClick:::mArrWeightList::: " + mIsDialogueClick);
if (!mIsDialogueClick) {
mIsDialogueClick = true;
showDialogBox(mDialogFor, txtWeight, getString(R.string.alert_select_weight));
}
}
break;
}
} catch (Exception e) {
e.printStackTrace();
Log.debug(getClass().getSimpleName(), e.getMessage());
Log.error(getClass().getSimpleName(), e.getMessage());
}
if (WebInterface.isOnline(mActivity)) {
new ApiProductDetail(mActivity, handlerProductDetail, mProductId).execute();
} else {
Utils.showAlert(mActivity, getString(R.string.title_internet), getString(R.string.Check_Internet_connection), getString(R.string.ok));
}
private void showDialogBox(final int mDialogFor, final TextView text, String mHeaderText) {
TextView txtHeader;
mDialog = new Dialog(mActivity);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
mDialog.setContentView(R.layout.dialog_list);
//mDialog.setCanceledOnTouchOutside(true);
listItem = (ListView) mDialog.findViewById(R.id.listFilter);
txtHeader = (TextView) mDialog.findViewById(R.id.txtHeader);
txtHeader.setText(mHeaderText);
listItem.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mIsDialogueClick = false;
}
});
mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mIsDialogueClick = false;
}
});
if (mDialogFor == 1) {
mProductDetailDialogAdapter = new ProductDetailDialogAdapter(mActivity, mArrWeightList);
listItem.setAdapter(mProductDetailDialogAdapter);
} else if (mDialogFor == 2) {
mTimeListAdapter = new TimeListAdapter(mActivity, mArrTimeList);
listItem.setAdapter(mTimeListAdapter);
} else if (mDialogFor == 3) {
mOccasionListAdapter = new OccasionListAdapter(mActivity, mArrOccasionList);
listItem.setAdapter(mOccasionListAdapter);
}
listItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mDialog.dismiss();
mIsDialogueClick = false;
switch (mDialogFor) {
case 1:
text.setText(mArrWeightList.get(position).weight);
mWeightPrice = Double.parseDouble(mArrWeightList.get(position).product_price + "");
mWeightId = mArrWeightList.get(position).weight_id;
break;
}
calculatePrice();
}
});
mDialog.show();
}
private Handler handlerProductDetail = new Handler() {
public void handleMessage(android.os.Message msg) {
try {
if (msg.what == 0) {
// ApiDashboard
if (msg.arg1 == 1) {
productListArrayList = (ArrayList<ProductListBean>) msg.obj;
if (productListArrayList != null && productListArrayList.size() > 0) {
mArrWeightList = productListArrayList.get(0).mArrWeightList;
if (mArrWeightList == null) {
ll_weight.setVisibility(View.GONE);
} else {
for (int i = 0; i < mArrWeightList.size(); i++) {
if (mWeightId.equals(mArrWeightList.get(i).weight_id)) {
mWeightPrice = mArrWeightList.get(i).product_price;
}
}
}
}
} else if (msg.arg1 == 2) {
showSnackbar(mViewPager, getString(R.string.no_data_found));
}
}
} catch (Exception e) {
e.printStackTrace();
Log.error(this.getClass().getSimpleName(), e);
Log.debug(this.getClass().getSimpleName(), e + "");
}
}
};