Delete current crime from CrimePagerActivity on back press


#1

How can I delete current crime from CrimePagerActivity?
CrimeLab.get(this).deleteCrime(crime);
finish();
doesnt work correctly

I am using to delete the current crime, but it also makes the previous item without a title.

I am setting the flag variable is 1 text has been entered and if flag=0 the title field is blank.

[code] @Override
public void onBackPressed() {
// Do Here what ever you want do on back press;

    Log.d(TAG, "Back was pressed. Flag: " + CrimeFragment.flag);

    if(CrimeFragment.flag == 1) {

// && mTitleField.getText().toString().length()>0
finish();
}
if(CrimeFragment.flag == 0)
{
// Toast.makeText(getApplicationContext(), “Enter a title”,
// Toast.LENGTH_LONG).show();
CrimeLab.get(this).deleteCrime(crime);
finish();
}

}

[/code]

and here is my mTitleField addTextChangedListener

[code] mTitleField.addTextChangedListener(new TextWatcher(){

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onTextChanged(CharSequence s, int start, int before,
				int count) {
			mCrime.setTitle(s.toString());


		}

		@Override
		public void afterTextChanged(Editable s) {


                     if(TextUtils.isEmpty(mTitleField.getText()))
                     {
                           flag = 0;
                     }

                    if(!TextUtils.isEmpty(mTitleField.getText()))
                    {
                         flag = 1;
                    }

		}
		
		
	});[/code]