尝试拍摄照片后,我的应用程序将刷新到我的菜单,而不是在ImageView中显示

时间:2014-08-05 16:26:43

标签: java android camera

正如标题所说:我正在尝试实现一个按钮,我可以用来打开我的应用程序运行的设备提供的相机,然后在我的应用程序中以ImageView显示它。我是从不同的类和布局而不是从我的主菜单中执行此操作。在拍完照片之后,它不会让我在我的ImageView中看到它,它位于我的AddRechnung.xml中,但它会让我回到我的主菜单。

public class AddRechnung extends Activity implements View.OnClickListener{


Spinner s;
Button GoBack2,AddRechnungHin;
Intent GoBackToMain2, iCam;
ImageButton ibCam;
ImageView ivCam;
final static int cameraData = 0;
Bitmap bmp;
private String array_spinner[];
public static int Nahrung,Kleidung,Miete,Feiern;
String RechnungString = "";
EditText RechnungValue;


@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addrechnung);
    LoadVariables();
    GoBack2.setOnClickListener(this);       
    s = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, array_spinner);
    s.setAdapter(adapter);      
    AddRechnungHin.setOnClickListener(this);
    ibCam.setOnClickListener(this);

}

private void LoadVariables() {
    // TODO Auto-generated method stub
    GoBackToMain2 = new Intent("com.lunarrepublic.STARTINGPOINT");
    GoBack2 = (Button) findViewById(R.id.button6);
    RechnungValue = (EditText) findViewById(R.id.editText2);
    array_spinner = new String[4];
    array_spinner[0] = "Nahrung";
    array_spinner[1] = "Kleidung";
    array_spinner[2] = "Miete";
    array_spinner[3] = "Feiern";
    AddRechnungHin = (Button) findViewById(R.id.button9);
    ibCam = (ImageButton) findViewById(R.id.ibCamera);
    ivCam = (ImageView) findViewById(R.id.ivCamera);
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.button6:
        startActivity(GoBackToMain2);
        break;
    case R.id.button9:
        RechnungString = RechnungValue.getText().toString();
        if(s.getSelectedItem().toString().equals("Nahrung")){
            Nahrung = Integer.parseInt(RechnungString);
        }else if (s.getSelectedItem().toString().equals("Kleidung")){
            Kleidung = Integer.parseInt(RechnungString);
        }else if (s.getSelectedItem().toString().equals("Miete")){
            Miete = Integer.parseInt(RechnungString);
        }else if (s.getSelectedItem().toString().equals("Feiern")){
            Feiern = Integer.parseInt(RechnungString);
        }
        startActivity(GoBackToMain2);
        break;
    case R.id.ibCamera:
        iCam = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(iCam, cameraData);
        break;
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        bmp = (Bitmap) extras.get("data");
        ivCam.setImageBitmap(bmp);
    }
}

}

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"
    android:orientation="vertical" >

     <Button
        android:id="@+id/button6"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="28dp"
        android:text="Zurück"
        android:textSize="7dp" />

     <EditText
         android:id="@+id/editText2"
         android:layout_width="120dp"
         android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
         android:layout_below="@+id/button6"
         android:layout_marginRight="50dp"
         android:layout_marginTop="20dp"
         android:ems="10" >

         <requestFocus />
     </EditText>

     <TextView
         android:id="@+id/textView2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/textView1"
         android:layout_below="@+id/textView1"
         android:text="eingeben und im"
         android:textSize="12dp"
         android:textAppearance="?android:attr/textAppearanceSmall" />

     <Button
         android:id="@+id/button9"
         android:layout_width="fill_parent"
         android:layout_height="40dp"
         android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
         android:layout_marginBottom="39dp"
         android:gravity="center"
         android:text="Rechnung hinzufügen" />

     <TextView
         android:id="@+id/textView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignBottom="@+id/editText2"
         android:layout_alignParentLeft="true"
         android:layout_marginLeft="14dp"
         android:text="Wert der Rechnung"
         android:textAppearance="?android:attr/textAppearanceSmall"
         android:textSize="12dp" />

     <TextView
         android:id="@+id/textView3"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/textView2"
         android:layout_below="@+id/textView2"
         android:text="Menü Kategorie wählen"
         android:textAppearance="?android:attr/textAppearanceSmall"
         android:textSize="12dp" />

     <Spinner
         android:id="@+id/spinner1"
         android:layout_width="120dp"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/editText2"
         android:layout_alignTop="@+id/textView2" />

     <ImageView
         android:id="@+id/ivCamera"
         android:layout_width="150dp"
         android:layout_height="150dp"
         android:layout_below="@+id/spinner1"
         android:layout_centerHorizontal="true"
         android:gravity="center"
         android:src="@drawable/ic_launcher" />

     <ImageButton
         android:id="@+id/ibCamera"
         android:layout_width="40dp"
         android:layout_height="40dp"
         android:layout_below="@+id/ivCamera"
         android:layout_toRightOf="@+id/textView3"
         android:src="@drawable/camera" />

     <TextView
         android:id="@+id/tvCamera"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_below="@+id/ibCamera"
         android:layout_centerHorizontal="true"
         android:paddingBottom="10dp"
         android:text="Rechnung fotografieren (optional)"
         android:textSize="10dp" />

</RelativeLayout>

我的项目中没有错误。

提前致谢

0 个答案:

没有答案