这是一个类似于京东客户端首页的界面。
需求: 对用户的账号进行判断,当它的账号被封禁时,用户点击这个页面的任意礼品类型列表,
会弹出一个自定义的Dialog,呈现给用户,账号已被封禁。
问题:现在用户的状态是冻结。。。自定义的Dialog始终弹不出来。(自定义的Dialog没有问题,已Demo测试过, 我怀疑是不是这个类的调用的问题)
求大神解答 !
/**
礼品部分activity
*/
public class GiftActivity extends BaseActivity {
/** 礼品类型列表 */
private final String giftListClass = GiftListFragment.class.getName();
/** 礼品详情 界面 */
private final String giftDetailClass = GiftDetailFragment.class.getName();
/** 礼品兑换界面 */
private final String giftChargeClass = GiftChargeFragment.class.getName();
private Fragment mFragment;
protected static FragmentActivity mmContext;
private static Handler mHandler;
private static CustomWebView mWebView;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.layout_gift);
initVariable();
}
/**
* 初始化变量
*/
private void initVariable() {
int type = getIntent().getIntExtra("type", 0);
switch (type) {
case 0:
initView(giftListClass, null);
break;
case 1:
initView(giftDetailClass, getIntent().getExtras());
break;
case 2:
initView(giftChargeClass, getIntent().getExtras());
break;
default:
break;
}
}
/**
* 初始化布局
*/
private void initView(String className, Bundle bundle) {
if (null != mContext) {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
mFragment = Fragment.instantiate(mContext, className, bundle);
ft.add(R.id.layout_gift_fragment_container, mFragment, className);
ft.commit();
}
}
/**
* 礼品列表
*
* @param context
*/
public static void start4GiftList(Context context) {
start(context, 0, null);
}
/**
* 礼品详情
*
* @param context
*/
public static void start4GiftDetail(final Context context,final GiftType value) {
// 增加一个判断的方式,当用户未登陆的情况下,进一步点击商品时调出登陆层
if (!HZApplication.get().isLogin()) {
Intent intent = new Intent(context, AccountActivity.class);
context.startActivity(intent);
} else {
// 当出现异常订单时,商品不可进一步兑换,出现封禁的状态,需要申请解禁。
NetworkController.getInstance(HZApplication.get()).getUserinfo(
new NetworkCallBack() {
@Override
public void response(String response) {
UserInfo mUserInfo = UserInfo.parser(response);
int mstatus = mUserInfo.status;
if (0 == mstatus) {
// 封禁
//banned();
} else if (1 == mstatus) {
// 正常 不做操作
Bundle bundle = new Bundle();
bundle.putSerializable("data", value);
start(context, 1, bundle);
} else if (2 == mstatus) {
// 1、冻结
Freeze();
}
}
@Override
public void error(int errorCode, String errorLog) {
}
});
}
}
/**
* 礼品兑换
*
* @param context
*/
public static void start4GiftCharge(Context context, GiftType value) {
Bundle bundle = new Bundle();
bundle.putSerializable("data", value);
start(context, 2, bundle);
}
/**
* 冻结状态
*/
private static void Freeze() {
CustomDialog.Builder builder = new CustomDialog.Builder(mmContext);
builder.setTitle("兑换冻结");
builder.setMessage("您的账号存在获取收入的异常操作,兑换功能被暂时冻结,冻结期间,获取经验值不受影响");
builder.setPositiveButton("申请解冻", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//设置你的操作事项
//Toast.makeText(getApplicationContext(),"Hi", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("了解规则",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Toast.makeText(getApplicationContext(),"Hi。。。。。", Toast.LENGTH_SHORT).show();
}
});
builder.create().show();
}
/**
* 启动
*
* @param context
* 上下文
* @param type
* 显示类型 0==礼品列表 1==礼品详情 2==礼品兑换 3==
*/
private static void start(Context context, int type, Bundle bundle) {
Intent intent = new Intent(context, GiftActivity.class);
intent.putExtra("type", type);
if (null != bundle) {
intent.putExtras(bundle);
}
context.startActivity(intent);
}
}
查看一下mmContext,它是否正确指向了UI Activity?(你的代码中,前面成员声明是mmContext,但初始化布局那里是mContext。但我估计是粘代码时候的问题,不然这会报error)
另外可以试着将dialog的调用放到异步任务中执行。
这个里面的mmContext是我自己定义出来的,mContext是基类的,你看看,我也纳闷,不知道怎么做。。。反正没报错。
应用程序Activity的基类
*/
public class BaseActivity extends FragmentActivity {
private int currentApiVersion = 0;
protected boolean isLoading = false;
protected FragmentActivity mContext = this;
protected boolean enabled = false;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
currentApiVersion = android.os.Build.VERSION.SDK_INT;
HZApplication.get().addActivity(this);
}
=========================相当于我这个类继承BaseActivity=====================
*/
public class GiftActivity extends BaseActivity {
/** 礼品类型列表 */
private final String giftListClass = GiftListFragment.class.getName();
/** 礼品详情 界面 */
private final String giftDetailClass = GiftDetailFragment.class.getName();
/** 礼品兑换界面 */
private final String giftChargeClass = GiftChargeFragment.class.getName();
private Fragment mFragment;
protected static FragmentActivity mmContext;
private static Handler mHandler;
private static CustomWebView mWebView;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.layout_gift);
initVariable();
}
麻烦你再帮我分析一下context.谢谢!