I'm new to android, Now I still building an app that consist with Two Activities First is LoginPage and it works well, the second is UserPage the problem starts here. I create Two ImageView on UserPage, what I want is
- Click on the ImageView
- Take a picture from a Camera
- save it to selected ImageView
When I Click the First ImageView and save the picture from camera it works well, The Problem starts when I click the second imageview, when I take a picture and save it to second imageview, the picture in first imageview is gone
This is my code : user.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/image1"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="centerInside" />
<ImageView
android:id="@+id/image2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_toRightOf="@id/image1"
android:layout_alignTop="@id/image1"
android:scaleType="centerInside" />
</RelativeLayout>
UserPage.java
public class UserPage extends Activity {
ImageView imageView1, imageView2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user);
imageView1 = (ImageView)findViewById(R.id.image1);
imageView1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, 1);
}
});
imageView2 = (ImageView)findViewById(R.id.image2);
imageView2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent ii = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(ii, 2);
}
});
}//OnCreate
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
Bitmap userImage = (Bitmap)data.getExtras().get("data");
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case 1:
if(resultCode == RESULT_OK){
Bundle extras = data.getExtras();
userImage = (Bitmap) extras.get("data");
imageView1.setImageBitmap(userImage);
}//if resultCode Case 1
break;
case 2:
if(resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
userImage = (Bitmap) extras.get("data");
imageView2.setImageBitmap(userImage);
}//if resultCode Case 2
}//Switch
}//onActivityResult
}//UserPage
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pramana.report"
android:versionCode="2"
android:versionName="1.1" >
<uses-sdk
android:minSdkVersion="8"
/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.camera"></uses-feature>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.pramana.report.UserPage"></activity>
</application>
</manifest>
Please Help, I've already search and try some of suggestion like Take multiple images with camera and insert into multiple diffefent imageViews but it did not work
Sorry for my bad English I'm not too good in English