我有一个公司列表,我正在打开一个对话框,用于登录特定公司。这在网上很好用。现在我的要求是将此应用程序也移到离线状态。当我点击列表的特定行时,我正在崩溃并在应用程序离线时抛出InflateExeption。 这是我的对话方法。
public void showDialog(){
dialog = new Dialog(context);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_login);
dialog.setCancelable(true);
// set the custom dialog components - text, image and button
EditText username = (EditText) dialog.findViewById(R.id.cusername);
EditText password = (EditText) dialog.findViewById(R.id.cpassword);
CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.remember_password);
LinearLayout submit = (LinearLayout) dialog.findViewById(R.id.submit);
LinearLayout close = (LinearLayout) dialog.findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
InputMethodManager inputManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
dialog.dismiss();
}
});
for (int i = 0; i < appUser.companyLoginArray.size(); i++) {
Map map = appUser.companyLoginArray.get(i);
String position = (String) map.get("position");
if (pos == Integer.parseInt(position)) {
Boolean status = (Boolean) map.get("status");
String uName = (String) map.get("username");
String pass = (String) map.get("password");
if (status) {
checkBox.setChecked(true);
username.setText(uName);
password.setText(pass);
}
}
}
// if button is clicked, close the custom dialog
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputMethodManager inputManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(v.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
appUser.boolSetOrAddtoMap=false;
appUser.company_logo=data.get(pos).getAttributes().getLogo();
appUser.company_state=data.get(pos).getAttributes().getState();
LocalRepositories.saveAppUser(context,appUser);
Map mapAdd= new HashMap();
if (!username.getText().toString().equals("")) {
if (!password.getText().toString().equals("")) {
appUser.cusername = username.getText().toString();
appUser.cpassword = password.getText().toString();
LocalRepositories.saveAppUser(context, appUser);
dialog.dismiss();
if (checkBox.isChecked()) {
mapAdd.put("position", String.valueOf(pos));
mapAdd.put("username", username.getText().toString());
mapAdd.put("password", password.getText().toString());
mapAdd.put("status", true);
for (int i=0;i<appUser.companyLoginArray.size();i++){
Map mapGet=appUser.companyLoginArray.get(i);
String str= (String) mapGet.get("position");
Integer integer= Integer.valueOf(str);
if (integer==Integer.valueOf(pos)){
LocalRepositories.saveAppUser(context,appUser);
appUser.companyLoginArray.set(i,mapGet);
LocalRepositories.saveAppUser(context, appUser);
}
}
if (!appUser.boolSetOrAddtoMap){
appUser.companyLoginArray.add(mapAdd);
LocalRepositories.saveAppUser(context, appUser);
}
} else {
for (int i = 0; i < appUser.companyLoginArray.size(); i++) {
Map mapRemove = appUser.companyLoginArray.get(i);
String position = (String) mapRemove.get("position");
if (pos ==Integer.valueOf(position)) {
appUser.companyLoginArray.remove(i);
LocalRepositories.saveAppUser(context, appUser);
}
}
}
EventBus.getDefault().post(new EventOpenCompany(pos));
} else {
Toast.makeText(context, "Enter password", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(context, "Enter username", Toast.LENGTH_LONG).show();
}
}
});
dialog.show();
}