Currently I create an app which has the camera function that allows users to select their image or do capturing.I get the tutorial from https://stackoverflow.com/a/22165449/5261462. But I want the selected image intent to another page instead of just displaying on imageView. The image need to fix the screen and can add caption at below like whatsapp.
This is what I've tried so far.
Everything start from Project1.java, with the imagebutton
.
public void addListenerOnButton() {
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
ImageFitScreen i = new ImageFitScreen();
i.selectImage();
}
});
}
ImageFitScreen.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_fit_screen);
b = (ImageView) findViewById(R.id.imageView3);
t = (EditText) findViewById(R.id.editText38);
u = (EditText) findViewById(R.id.editText39);
}
public void selectImage() {
final CharSequence[] options = { "Take Photo", "Choose from Gallery","Cancel" };
AlertDialog.Builder builder = new AlertDialog.Builder(ImageFitScreen.this);
builder.setTitle("Add Photo!");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Take Photo"))
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
}
else if (options[item].equals("Choose from Gallery"))
{
Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 2);
}
else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
image_fit_screen
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="574dp"
android:layout_height="523dp"
android:id="@+id/imageView3"
android:layout_x="6dp"
android:layout_y="0dp" />
<EditText
android:layout_width="388dp"
android:layout_height="wrap_content"
android:id="@+id/editText38"
android:layout_x="8dp"
android:layout_y="435dp" />
<EditText
android:layout_width="386dp"
android:layout_height="wrap_content"
android:id="@+id/editText39"
android:hint="Add a caption"
android:layout_x="2dp"
android:layout_y="410dp" />
</AbsoluteLayout>
But I get error as below when the imageButton
in Project1.java is clicked.
11-03 11:44:44.800 31219-31219/com.example.project.project E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.project.project, PID: 31219 java.lang.NullPointerException at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:164) at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103) at android.support.v7.app.AlertDialog.resolveDialogTheme(AlertDialog.java:108) at android.support.v7.app.AlertDialog$Builder.(AlertDialog.java:269) at com.example.project.project.ImageFitScreen.selectImage(ImageFitScreen.java:77) at com.example.project.project.Project1$2.onClick(Project1.java:80) at android.view.View.performClick(View.java:4654) at android.view.View$PerformClick.run(View.java:19438) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:146)
(ImageFitScreen.java:77)
AlertDialog.Builder builder = new AlertDialog.Builder(ImageFitScreen.this);
(Project1.java:80)
i.selectImage();
I am seriously in dire need of some advice. Can someone please please assist me with some advice. PLEASE : )?