wie erstelle Datenbank und speichern Sie Daten in die Datenbank ein, wenn jemand schreiben in EditText in android?

ich bin neu bei android, in meiner Anwendung brauche ich zum erstellen der Datenbank und wenn der user das schreiben von etwas, was in EditText dann muss ich mir speichern es in die Datenbank ein, aber ich weiß nicht, wie ich bin gonna es tun. also bitte jemand mir helfen.ich habe bereits ein submit-button zum speichern der Daten, die ich jetzt erstellen muss nur eine Datenbank.

hier bin ich einem meine activity-Klasse mit Namen "Invitation.java" enthält

         package com.ggit.trip.caster;

     import android.content.Intent;
     import android.os.Bundle;
     import android.util.Log;
     import android.view.View;
     import android.view.View.OnClickListener;
     import android.widget.Button;
     import android.widget.EditText;

    public class Invitation extends AppBaseActivity {

protected static final String Tag = "Invitation Activity";

private Button submit2;
private Button exit2;

private EditText Edit1;
private EditText Edit2;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.invitation);

    registerBaseActivityReceiver();

    submit2 = (Button) findViewById(R.id.sub2_button1);
    exit2=(Button)findViewById(R.id.button2);

    Edit1 = (EditText) findViewById(R.id.editText1);
    Edit2 = (EditText) findViewById(R.id.editText2);

    submit2.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            Log.d(Tag, "EditText : " + Edit1.getText().toString());
            Log.d(Tag, "EditText : " + Edit2.getText().toString());

            Intent intent = new Intent(getApplicationContext(),
                    Registration.class);
            startActivity(intent);
        }
    });

    exit2.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            closeAllActivities();
                   }
    });
}

public void onDestroy() {

    super.onDestroy();
    unRegisterBaseActivityReceiver();
}

    }

nun hier die xml-layout für die Einladung.jave-Klasse mit Namen "invitation.xml" enthält

<?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:background="@drawable/sea_01"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView3"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="28dp"
    android:text="E-mail"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="160dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:background="@drawable/rounded_edittext"
    android:ems="10"
    android:hint="     email address"
    android:inputType="textEmailAddress" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/editText1"
    android:text="Phone"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="160dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText1"
    android:layout_below="@+id/textView2"
    android:background="@drawable/rounded_edittext"
    android:ems="10"
    android:hint="    phone number"
    android:inputType="phone" />

<Button
    android:id="@+id/sub2_button1"
    android:layout_width="100dp"
    android:layout_height="45dp"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/textView1"
    android:layout_marginRight="27dp"
    android:background="@drawable/gloss_nine_patch"
    android:text="Send Invitation" />

<Button
    android:id="@+id/button2"
    android:layout_width="100dp"
    android:layout_height="45dp"
    android:layout_alignLeft="@+id/textView2"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="32dp"
    android:background="@drawable/gloss_nine_patch"
    android:text="Exit" />

 </RelativeLayout>

nun muss ich das speichern der Daten in die Datenbank für diese beiden EditText.bitte schreiben Sie eine korrekte oder vollständige Tätigkeiten, weil ich die Klasse m einen neuen Mann. Danke.


DataHelper.java für @Naser

package i.am.arnob;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DataHelper  extends SQLiteOpenHelper{

//database version, current ver is 1.
public static final int DATABASE_VER=1;

//database Name or db name
public static final String DATABASE_NAME="dataPerson";

//table Name, table person
public static final String TABLE_PERSON="person";

//table fields name,fist name,email and domain
//public static final String KEY_NAME="name";
//public static final String KEY_FIRST_NAME="first_name";
public static final String KEY_EMAIL="email";
public static final String KEY_DOMAIN="domain";

public DataHelper(Context context, String name, CursorFactory factory,
        int version) {
    super(context, name, factory, version);
    //TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
    //TODO Auto-generated method stub
    //creating string sqlTable for creating a table 
    String sqlTable = "create table " +TABLE_PERSON+ "("/* +KEY_NAME+ " text," +KEY_FIRST_NAME+ " text," */ +KEY_EMAIL+ " text," +KEY_DOMAIN+ " text);"; 
    //db.execSQL() will execute string which we provide and will create a  table with given table name and fields.
    db.execSQL(sqlTable);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    //TODO Auto-generated method stub

}

}
  • Sie haben versucht, eine Datenbank zu erstellen in android
  • auf sqlite oder auf die Datenbank auf dem server ? klar machen...
  • ja, ich möchte erstellen Sie eine Verbindung mit der Datenbank @nick
  • ich habe keine Ahnung, was ich bin gonna zu verbinden bitte geben Sie mir einen Vorschlag und hepl mich @Narayan Kandel
  • Zunächst entsprechen sich, ob Datenbank speichern am server oder am android-Gerät und müssen die Daten zum speichern in android verwenden Sie dann sqlite ansonsten können Sie auch mysql database with json api...
  • danke, eigentlich möchte ich verbinden mit der sqlite Datenbank, aber ich kann es nicht getan werden kann u helfen, m @Narayan Kandel

InformationsquelleAutor Aces | 2012-09-01
Schreibe einen Kommentar