Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:14:33+00:00 2026-06-16T00:14:33+00:00

I have a problem. When I click ADD exercise and open ADD dialog to

  • 0

I have a problem. When I click “ADD exercise” and open ADD dialog to put some info everything works good even when I rotate device. But when I rotate device with “EDIT dialog” the APP is crashing
Please, help me.
Need something to prevent it. (I’m not programmer, so its not easy for me)

public class ShowExercisesListActivity extends ListActivity {

private static final String TAG = "Exercises";

private List<Exercise> mExercises;
private LayoutInflater mInflater;
private ArrayAdapter<Exercise> mArrayAdapter;
private View mAddExerciseDialogLayout;
private Context mContext;
private EditText exerciseName;

private static final int DIALOG_ADD_EXERCISE = 0;

 // package scope, since it is accessed in inner classes
WorkoutTrackerApp mApp;

/** 
 * Called when the activity is first created. 
 * 
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.type_list);

    mApp = (WorkoutTrackerApp) getApplication();
    mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mExercises = DBUtil.fetchAllExercises(this);

    mArrayAdapter = new ArrayAdapter<Exercise>(this, R.layout.type_list_item, mExercises) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row;

            if (null == convertView) {
                row = mInflater.inflate(R.layout.type_list_item, null);
            } else {
                row = convertView;
            }

            Exercise type = (Exercise) mExercises.get(position);
            TextView tv = (TextView) row.findViewById(android.R.id.text1);
            tv.setText(type.getName());

            return row;
        }

    };
    setListAdapter(mArrayAdapter);

    //dialog box layout
    mContext = this;
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    mAddExerciseDialogLayout = inflater.inflate(R.layout.add_type_dialog, (ViewGroup) findViewById(R.id.type_layout_root));



    exerciseName = (EditText) mAddExerciseDialogLayout.findViewById(R.id.type_name);
    //register for context menu
    registerForContextMenu(getListView());      

    if (mExercises.size() == 0) {
        // if there are no exercises initially, then show the add type dialog
        showDialog(DIALOG_ADD_EXERCISE);            
    }



    //Начало:Активация кнопки "Добавить упражнение"
    Button addExerciseButton = (Button) findViewById(R.id.menu_add_exercise);
    addExerciseButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mApp.setCurrrentDialogStatus(DialogStatus.ADD);
            showDialog(DIALOG_ADD_EXERCISE);
        }
    });
    //Конец: Активация кнопки "Добавить упражнение"


    //Начало:Активация иконки Верхней плашки
    ImageButton GoHomeButton = (ImageButton) findViewById(R.id.imageButton1);
    GoHomeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent myIntent5 = new Intent(ShowExercisesListActivity.this, AndroidApp.class);
            ShowExercisesListActivity.this.startActivity(myIntent5);
        }
    });
    //Конец:Активация иконки Верхней плашки
}






@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Exercise type = mExercises.get(position);
    Log.v(TAG, "Clicked " + type.getName() + "Id: " + type.getId());

    Intent intent = new Intent(this.getApplicationContext(),
            TabWidget.class);
    intent.putExtra("typeId", type.getId());
    startActivity(intent);
}

/**
 * When the context menu is created
 * 
 * @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu, android.view.View, android.view.ContextMenu.ContextMenuInfo)
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.exercise_context_menu, menu);
}



/**
 * When a context menu item is selected
 *  
 * @see android.app.Activity#onContextItemSelected(android.view.MenuItem)
 */
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {

    case R.id.edit_exercise:
        //Edit Exercise name
        mApp.setCurrentExerciseDialogStatus(DialogStatus.EDIT);         
        editExercise((int) info.id);
        return true;
    case R.id.delete_exercise:
        //Delete Exercise and all its entries
        deleteExercise((int) info.id);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

/*
 * (non-Javadoc)
 * 
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.types_menu, menu);
    return true;
}

/*
 * (non-Javadoc)
 * 
 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.add_exercise:
        mApp.setCurrentExerciseDialogStatus(DialogStatus.ADD);
        showDialog(DIALOG_ADD_EXERCISE);
        break;

    case R.id.home: // Go Back to local website
        Intent myIntent3 = new Intent(ShowExercisesListActivity.this, AndroidApp.class);
        ShowExercisesListActivity.this.startActivity(myIntent3);
        return true;

    case R.id.close: // Close WebView
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent); 
        return true;
    case R.id.google: // Open new WebView with the e.g. Google Url
        startActivity(new Intent(Intent.ACTION_VIEW, 
                Uri.parse("http://vk.com/gymtraining")));

        return true;

    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

/* (non-Javadoc)
 * @see android.app.Activity#onCreateDialog(int)
 */
@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;
    switch (id) {
    case DIALOG_ADD_EXERCISE:
        AlertDialog.Builder builder;

        //build the dialog
        builder = new AlertDialog.Builder(mContext);
        builder.setView(mAddExerciseDialogLayout);
        builder.setMessage(this.getString(R.string.add_exercise_title))
           .setCancelable(false)
           .setPositiveButton(this.getString(R.string.add, this.getString(R.string.exercise)), null)
           .setNegativeButton("Отмена", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
               }
           });

        dialog = builder.create();

        break;

    default:
        dialog = null;
        break;
    }
    return dialog;
}

/* (non-Javadoc)
 * @see android.app.Activity#onPrepareDialog(int, android.app.Dialog)
 */
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    AlertDialog alertDialog = (AlertDialog) dialog;
    Button positiveButton = null;

    switch (id) {
    case DIALOG_ADD_EXERCISE:

        switch (mApp.getCurrentExerciseDialogStatus()) {
        case DEFAULT:
        case ADD:

            alertDialog.setMessage(this.getString(R.string.add_exercise_title));
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, this.getString(R.string.add, this.getString(R.string.exercise)), new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       //Insert the new data into db
                       String typeName = exerciseName.getText().toString();
                       Exercise newExercise = DBUtil.insertExercise(mContext, typeName);

                       Toast.makeText(mContext, mContext.getResources().getString(R.string.exercise_saved), Toast.LENGTH_SHORT).show();

                       mArrayAdapter.add(newExercise);
                       mArrayAdapter.notifyDataSetChanged();
                   }
               });

            positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setText(this.getString(R.string.add, this.getString(R.string.exercise)));
            positiveButton.invalidate();

            exerciseName.setText("");

            break;

        case EDIT:
            alertDialog.setMessage(this.getString(R.string.edit, this.getString(R.string.exercise)));
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, this.getString(R.string.edit_button), new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       //Update the data into db
                        Exercise exerciseToEdit = (Exercise) exerciseName.getTag(); 
                        exerciseToEdit.setName(exerciseName.getText().toString());

                        DBUtil.updateExercise(mContext, exerciseToEdit);
                        Toast.makeText(mContext, mContext.getResources().getString(R.string.exercise_saved), Toast.LENGTH_SHORT).show();        
                        mArrayAdapter.notifyDataSetChanged();
                   }

               });

            Exercise exerciseToEdit = (Exercise) exerciseName.getTag();
            exerciseName.setText(exerciseToEdit.getName());

            positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setText(this.getString(R.string.edit_button));
            positiveButton.invalidate();

            break;
            }
    default:
        break;
    }
}

/**
 * Edit Exercise name
 * 
 * @param id
 */
private void editExercise(int position) {
    exerciseName.setTag(mExercises.get(position));
    showDialog(DIALOG_ADD_EXERCISE);
}

/**
 * Delete an Exercise
 * 
 * @param position
 */
private void deleteExercise(int position) {
    Exercise exercise = mExercises.get(position);
    DBUtil.deleteExercise(mContext, exercise.getId());

    Toast.makeText(mContext, mContext.getResources().getString(R.string.exercise_deleted), Toast.LENGTH_SHORT).show();      

    mArrayAdapter.remove(exercise);
    mArrayAdapter.notifyDataSetChanged();

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:14:33+00:00Added an answer on June 16, 2026 at 12:14 am

    I can’t go over the whole code right now but if your problem is only when you rotate the phone and it is not necessary to have the rotation activated, then why don’t you just add either of the following lines into your activity definition in your AndroidManifest.xml

    android:screenOrientation="portrait"
    

    or

    android:screenOrientation="landscape"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem I have : I click add I select 2nd option I click
I have problem while loading data into html select when users press or click
I have a problem that when I click on the image button instead of
I have a problem with an animation in jQuery using ajax. On the click
I have a problem... In my view i have Image.If i click on image
THIS IS THE FULL SCRIPT http://goo.gl/HoCxk I have a problem with this function: $('.message').click(function(){
i have this annoying problem with my site where, when you click on a
I have a list showing up when I click on button, the problem is
I have problem with script, can someone help me? //Add event to google maps
hi i have a image and i want to add a click event to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.