消息对话框加载不出来。从第一开始的测试加载就加载不出,自动退出
不知道为什么。那么Dialog一加载到那个Button类下面,长按就自动退出。。。
package com.example.administrator.my_recorder.view;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.administrator.my_recorder.R;
/**
* Created by Administrator on 2015/12/27.
*/
public class DialogManager {
private Dialog mDialog;
private ImageView mIcon;
private ImageView mVoice;
private TextView mLable;
private Context mContext;
public DialogManager(Context context) {
mContext=context;
}
public void showRecordingDialog(){
mDialog=new Dialog(mContext, R.style.Theme_AudioDialog);
LayoutInflater inflater=LayoutInflater.from(mContext);
View view=inflater.inflate(R.layout.dialog_recorder,null);
mDialog.setContentView(view);
mIcon=(ImageView)mDialog.findViewById(R.id.id_recorder_dialog_icon);
mVoice=(ImageView)mDialog.findViewById(R.id.id_recorder_dialog_voice);
mLable=(TextView)mDialog.findViewById(R.id.id_recorde_dialog_label);
mDialog.show();
}
public void recording(){
//判断mDialog不为空和正在显示
if(mDialog!=null && mDialog.isShowing()){
mIcon.setVisibility(View.VISIBLE);
mVoice.setVisibility(View.VISIBLE);
mLable.setVisibility(View.VISIBLE);
mIcon.setImageResource(R.mipmap.recorder);
mLable.setText(R.string.str_recorder_recording);
}
}
public void wangToCancell()
{
//判断mDialog不为空和正在显示
if(mDialog!=null && mDialog.isShowing()){
mIcon.setVisibility(View.VISIBLE); //显示
mVoice.setVisibility(View.GONE); //不显示
mLable.setVisibility(View.VISIBLE);
mIcon.setImageResource(R.mipmap.cancel);
mLable.setText(R.string.str_recorder_want_cancel);
}
}
public void tooShort()
{
if(mDialog!=null && mDialog.isShowing()){
mIcon.setVisibility(View.VISIBLE); //显示
mVoice.setVisibility(View.GONE); //不显示
mLable.setVisibility(View.VISIBLE);
mIcon.setImageResource(R.mipmap.voice_to_short);
mLable.setText("录音时间果断 取消");
}
}
public void dimissDialog(){
if(mDialog!=null && mDialog.isShowing()){
mDialog.dismiss(); //隐藏
mDialog=null;
}
}
/*
* 通过level 更新图片**/
public void updateVoiceLevel(int level) {
if (mDialog != null && mDialog.isShowing()) {
int resId=mContext.getResources().getIdentifier("v"+level,"mipmap",mContext.getPackageName());
mVoice.setImageResource(resId);
}
}
}