My main class has a public method called commitChanges(). My layout contains extended EditTexts which can detect when the back button is pressed, as suggested here: Get back key event on EditText
Now, when a back button press is detected, I need to execute commitChanges, which stores the content to an array. commitChanges needs access the activity's listview however.
The question is: how to access the commitChange function of the main activity? I will need the instance of the main activity. Heres the code of the extended EditText:
public class BackText extends EditText{
private static final String TAG = "baby";
public BackText(Context context) {
super(context);
}
public BackText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public BackText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) &&
event.getAction() == KeyEvent.ACTION_UP) {
Log.d(TAG,"keypad exit");
commitChange(this);
return false;
}
return super.dispatchKeyEvent(event);
}
}
Note i'm a beginner and this pretty advanced for me. Note 2: this has nothing to do with services/multiple activities. The BackTexts are placed in the main activity.