Android应用保存图像路径,然后从数据库中检索它

时间:2022-09-26 15:15:26

I am trying to do for each customer and destination should have a photo by saving the path of this photo in the database in order to retrieve it again.

我正在尝试为每个客户做,目的地应该有一张照片,通过在数据库中保存此照片的路径,以便再次检索它。

Here is my code:

这是我的代码:

package com.example.pr;

import ItemsAndDatabase.Destination_Item;
import ItemsAndDatabase.Flight_Item;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddDestination extends Activity {

    private int customer_id;
    private string name;
    private int passportNo;
    private int ID;
    private string addr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.add_new_destination);

        final EditText txtName = (EditText) findViewById(R.id.editText1);
        final EditText CusID = (EditText) findViewById(R.id.editText2);
        final EditText Pass = (EditText) findViewById(R.id.editText3);
        final EditText photo = (EditText) findViewById(R.id.editText4);
        final EditText Addr = (EditText) findViewById(R.id.editText5);

        Button btnAddNewcustomer = (Button) findViewById(R.id.button1);
        Button back = (Button) findViewById(R.id.button2);

        back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                finish();
                Intent myIntent = new Intent(AddDestination.this,
                        destination.class);
                AddDestination.this.startActivity(myIntent);
            }
        });




        btnAddNewcustomer.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (!txtName.getText().toString().isEmpty()
                        && !CusID.getText().toString().isEmpty()
                        && !Pass.getText().toString().isEmpty()) {
                    Destination_Item item = new Destination_Item();
                    item.setName(txtName.getText().toString());
                    item.setCountry(CusID.getText().toString() );
                    item.setLongg(Pass.getText().toString() );
                    item.setLatt(photo.getText().toString() );
                    item.setPhoto(Addr.getText().toString() );

                    MainActivity.db.addDestination(item);
                    Toast.makeText(AddDestination.this,
                            "Destination Added Successfully", Toast.LENGTH_LONG)
                            .show();
                    finish();

                } else {
                    Toast.makeText(AddDestination.this, "Please Fill All fields",
                            Toast.LENGTH_LONG).show();

                }

            }
        });

    }
}

And this is my XML file:

这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="10dip"
    android:layout_marginTop="10dip"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Name"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <EditText
                android:id="@+id/editText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10" >

                <requestFocus />
            </EditText>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Country"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <EditText
                android:id="@+id/editText2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Long"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <EditText
                android:id="@+id/editText3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Lat" />

            <EditText
                android:id="@+id/editText4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Photo"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <EditText
                android:id="@+id/editText5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10" />
        </TableRow>
    </TableLayout>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Add Destination" />

     <Button
         android:id="@+id/button2"
         android:layout_width="126dp"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
         android:text="back" />

</LinearLayout>

any idea how to do this ? thanks in advance.

任何想法如何做到这一点?提前致谢。

1 个解决方案

#1


0  

Are you going to let the user take a photo during the sign up? you should change the photo into an ImageView instead of using EditText.

您是否打算让用户在注册期间拍照?您应该将照片更改为ImageView而不是使用EditText。

If you are going let the user take a picture or use an image from gallery, use the developer in android or use Androidhive.com

如果您要让用户拍照或使用图库中的图像,请使用Android中的开发人员或使用Androidhive.com

#1


0  

Are you going to let the user take a photo during the sign up? you should change the photo into an ImageView instead of using EditText.

您是否打算让用户在注册期间拍照?您应该将照片更改为ImageView而不是使用EditText。

If you are going let the user take a picture or use an image from gallery, use the developer in android or use Androidhive.com

如果您要让用户拍照或使用图库中的图像,请使用Android中的开发人员或使用Androidhive.com