泄露的窗口错误..不知道该怎么做..请帮帮我......
评论你的答案plss ..
public class Profile extends Fragment{
int success;
View profiles;
JSONParser jsonParser = new JSONParser();
JSONObject json;
TextView tvName,tvNumber,tvEmail,tvUsername,tvPass,tvAddress,newmunber;
Button save;
String adminName, adminNumber,adminEmail,adminUsername,adminPassword,adminAddress;
String newnum;
Context context;
Dialog dialog;
private static final String PROFILE_URL = "http://jcasim.5gbfree.com/Project/JCASIM_Api/profile.php";
private static final String CHANGES_URL = "http://jcasim.5gbfree.com/Project/JCASIM_Api/changeNum.php";
private static final String TAG_SUCCESS = "success";
// private static final String TAG_ID = "id";
public Profile (){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View profiles = inflater.inflate(R.layout.profile, container,false);
tvName = (TextView)profiles.findViewById(R.id.tvAdminName);
tvNumber = (TextView)profiles.findViewById(R.id.tvAdminNumber);
tvEmail = (TextView)profiles.findViewById(R.id.tvAdminEmail);
tvUsername = (TextView)profiles.findViewById(R.id.tvAdminUsername);
tvPass = (TextView)profiles.findViewById(R.id.tvAdminPassword);
tvAddress = (TextView)profiles.findViewById(R.id.tvAdminAddress);
newmunber = (TextView)profiles.findViewById(R.id.inputNum);
save = (Button) profiles.findViewById(R.id.savenum);
new profile().execute();
TextView changeNumber = (TextView)profiles.findViewById(R.id.tvAdminChangNumber);
changeNumber.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new changenum().execute();
}
});
return profiles;
}
class profile extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
String addminObject ="";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("addminObject", addminObject));
json = jsonParser.makeHttpRequest(PROFILE_URL, "POST",params);
try {
// json success tag
success = json.getInt(TAG_SUCCESS);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
if (success == 1){
try {
JSONArray myarr = json.getJSONArray("addminObject");
for(int i =0; i<myarr.length();i++){
JSONObject s = myarr.getJSONObject(i);
String adminName = s.getString("CompleteName");
String adminNumber = s.getString("Number");
String adminEmail = s.getString("Email");
String adminUsername = s.getString("Username");
String adminPassword = s.getString("Password");
String adminAddress = s.getString("Address");
tvName.setText(adminName);
tvNumber.setText(adminNumber);
tvEmail.setText(adminEmail);
tvUsername.setText(adminUsername);
tvPass.setText(adminPassword);
tvAddress.setText(adminAddress);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
Toast.makeText(getActivity(), "Watwatwat", Toast.LENGTH_SHORT).show();
}
}
}
class changenum extends AsyncTask<String,String,String>{
int success;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.changenum);
dialog.setTitle("Change Number");
dialog.show();
}
@Override
protected String doInBackground(String... arg0) {
newnum = newmunber.getText().toString();
// TODO Auto-generated method s
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("newNum", newnum));
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(CHANGES_URL, "POST",
params);
try {
// json success tag
success = json.getInt(TAG_SUCCESS);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (success == 1){
Toast.makeText(getActivity(), "Number succesfully changed !", Toast.LENGTH_SHORT).show();
tvNumber.setText(newnum);
}else{
Toast.makeText(getActivity(), "Changes Failed !", Toast.LENGTH_SHORT).show();
}
}
});
}
}
}
这里是我的错误日志的打印屏幕..它指的是我的其他活动,即slidemenu
并且是我幻灯片中的代码。
public class Slidemenu extends FragmentActivity {
private static final String TAG = Slidemenu.class.getSimpleName();
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slidemenu);
mTitle = mDrawerTitle = getTitle();
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
navMenuIcons = getResources()
.obtainTypedArray(R.array.nav_drawer_icons);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
navDrawerItems = new ArrayList<NavDrawerItem>();
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons
.getResourceId(0, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons
.getResourceId(1, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons
.getResourceId(2, -1)));
// Communities, Will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons
.getResourceId(3, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons
.getResourceId(4, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons
.getResourceId(5, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons
.getResourceId(6, -1)));
navMenuIcons.recycle();
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);
mDrawerList.setAdapter(adapter);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer,
R.string.app_name,
R.string.app_name
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
navigateTo(0);
}
}
/**
* Slide menu item click listener
* */
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
navigateTo(position);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.slidemenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
/**
* Diplaying fragment view for selected nav drawer list item
* */
private void navigateTo(int position) {
Log.v(TAG, "List View Item: " + position);
switch (position) {
case 0:
getFragmentManager()
.beginTransaction()
.replace(R.id.frame_container, new HomeFragment()).commit();
break;
case 1:
getFragmentManager()
.beginTransaction()
.replace(R.id.frame_container, new Logout()).commit();
break;
case 2:
getFragmentManager()
.beginTransaction()
.replace(R.id.frame_container, new SalesFragment()).commit();
break;
case 3:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.frame_container, new ProductListTabs()).commit();
break;
case 4:
getFragmentManager()
.beginTransaction()
.replace(R.id.frame_container, new Logout()).commit();
break;
case 5:
getFragmentManager()
.beginTransaction()
.replace(R.id.frame_container, new SuppliersFragment()).commit();
break;
case 6:
getFragmentManager()
.beginTransaction()
.replace(R.id.frame_container, new Profile()).commit();
break;
}
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
}
答案 0 :(得分:0)
dismiss()
dialog
asynctask changenum
中的onPostExecute()
。
将成员变量Dialog dialog;
移到asynctask中,这样每个asynctask实例都有自己的对话框,不可能覆盖其他实例已经使用的变量,而且不会解除对话框。