-4

我正在创建一个 android 应用程序,在该应用程序中我使用一种表格进行查询。

单击查询按钮时,应用程序必须显示一个表单。在用户按下提交按钮时完成表单输入用户后,数据应保存在数据库中,表单详细信息必须通过邮件发送到管理员帐户。

我在谷歌搜索,但我没有得到我想要的确切信息。

这是我的代码

订单.java

package com.example.shaktitool;    
import android.app.Activity;
import android.os.Bundle;    
import android.view.View;    
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Order extends Activity{

    private SQLiteAdapterOrder mySQLiteAdapter;

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

        mySQLiteAdapter = new SQLiteAdapterOrder(this);    
        mySQLiteAdapter.openToWrite();
        mySQLiteAdapter.deleteAll();
        final MY_TABLE tb = new MY_TABLE(this);
        final EditText name   = (EditText)findViewById(R.id.username);
        final EditText mail   = (EditText)findViewById(R.id.email);
        final EditText phone   = (EditText)findViewById(R.id.phone);
        final EditText product   = (EditText)findViewById(R.id.product);
        final String _name = name.getText().toString();
        final String _mail = mail.getText().toString();
        final String _phone = phone.getText().toString();
        final String _product = product.getText().toString();

        System.out.println(_name);
        System.out.println(_mail);
        System.out.println(_phone);
        System.out.println(_product);

        Button email = (Button) findViewById(R.id.Button01);
        email.setOnClickListener(new View.OnClickListener(){    
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
                      tb.open();
                      final String _name = name.getText().toString();    
                      final String _mail = mail.getText().toString();    
                      final String _phone = phone.getText().toString();    
                      final String _product = product.getText().toString();

                      System.out.println(name);
                      Toast.makeText(getBaseContext(), "Record Saved",Toast.LENGTH_LONG).show();    
                      System.out.println(mail);
                      System.out.println(phone);       
                      System.out.println(product);

                      tb.createorders(name, mail, phone, product);
                      tb.delete("12");
                      tb.close();

                  }
              }); 
    }
}

谁能帮我...

4

2 回答 2

0
 EditText fd1 = (EditText)findviewById(R.id.fd1);
 EditText fd2 = (EditText)findviewById(R.id.fd2);
 EditText fd3 = (EditText)findviewById(R.id.fd3);

 submitbtn.setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            String field1 = fd1.getText.toString();
            String field2 = fd2.getText.toString();
            String field3 = fd3.getText.toString();
            dh.insert_values(field1, field2, field3);   
        }
    });

像这样将插入值提交到数据库中..

在你的 datahelper 类中

 public long insert_values(String fd1,String fd2,String fd3)
    {
       this.insertStmt.bindString(1, fd1);
       this.insertStmt.bindString(2, fd2);
       this.insertStmt.bindString(3, fd3);
       return this.insertStmt.executeInsert();
    }
于 2012-11-27T09:16:55.947 回答
0

通过以下链接。你会发现很好的例子:

  1. http://saigeethamn.blogspot.in/2009/10/android-developer-tutorial-part-12.html
  2. http://android-er.blogspot.in/2011/06/simple-example-using-androids-sqlite_02.html
  3. http://www.codeproject.com/Articles/119293/Using-SQLite-Database-with-Android

对于好的 SQL 教程,请通过此链接: http ://www.vogella.com/articles/AndroidSQLite/article.html

DBInsert 方法示例:

public Marks addMarks(Marks comment) {
        
        ContentValues values = new ContentValues();
        values.put(MarksDB.MARKS_StdNo, comment.getStdNo());
        values.put(MarksDB.MARKS_1, comment.getSub_1());
        values.put(MarksDB.MARKS_2, comment.getSub_2());
        values.put(MarksDB.MARKS_3, comment.getSub_3());
        values.put(MarksDB.MARKS_4, comment.getSub_4());
        values.put(MarksDB.MARKS_5, comment.getSub_5());
        
        long insertId = database.insert(MarksDB.TABLE_MARKS, null, values);

在从数据库中插入和删除时,保持模态类从模态类中获取对象并设置属性。然后插入 Modal 类的当前对象。这对于 DBTransactions 来说是一种很好且不会令人困惑的方式。

于 2012-11-27T11:01:16.770 回答