Skip to content

Instantly share code, notes, and snippets.

View mitchtabian's full-sized avatar
🎞️
Building stuff

Mitch Tabian mitchtabian

🎞️
Building stuff
View GitHub Profile
@Override
public void onAttach(Context context) {
super.onAttach(context);
try{
mOnInputListener = (OnInputListener) getActivity();
}catch (ClassCastException e){
Log.e(TAG, "onAttach: ClassCastException: " + e.getMessage() );
}
}
mOnInputListener.sendInput(input);
getDialog().dismiss();
public class MainActivity extends AppCompatActivity implements MyCustomDialog.OnInputListener {
private static final String TAG = "MainActivity";
@Override
public void sendInput(String input) {
Log.d(TAG, "sendInput: got the input: " + input);
mInputDisplay.setText(input);
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="codingwithmitch.com.dialogfragmentfragment.MainActivity">
<FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="codingwithmitch.com.dialogfragmentfragment.MainActivity">
<TextView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="codingwithmitch.com.dialogfragmentfragment.MainActivity"
>
package codingwithmitch.com.dialogfragmentfragment;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
package codingwithmitch.com.dialogfragmentfragment;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
package codingwithmitch.com.dialogfragmentfragment;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
mOpenDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: opening dialog");
MyCustomDialog dialog = new MyCustomDialog();
dialog.setTargetFragment(MainFragment.this, 1);
dialog.show(getFragmentManager(), "MyCustomDialog");
}
});