Sunday, May 9, 2010

Reprogram Ml320 Remote

Exercise Database 3 for home

Android Create a program that reads and writes in the "information" contained in the database "Studente.db" data: name, address and email.

------------------- ------------------- 2 AndroidManifest.xml 3 \u0026lt;? xml version = "1.0" encoding = "UTF-8"?> \u0026lt;manifest xmlns: android = "

http://schemas.android.com/apk/res/android" \u0026lt;application>

\u0026lt;activity android:name=".Agenda" android:label="Agenda">

; \u0026lt;intent-filter>

& # 160; \u0026lt;action android:name="android.intent.action.MAIN"/> & # 160; \u0026lt;category android:name="android.intent.category.LAUNCHER"/> ; \u0026lt;/ intent -filter>

\u0026lt;/ Activity>

\u0026lt;activity android:name=".Lista"> \u0026lt; / activity>
\u0026lt;/ application> \u0026lt;/ manifest>


--------------- ---- -------------------
lista.xml


\u0026lt;? xml version = "1.0" encoding = "UTF-8"? >
\u0026lt;relative layout xmlns: android = "
http://schemas.android.com/apk/res/android "

android: orientation =" horizontal "

& # 160; android: layout_width = "fill_parent"

android: layout_height = "fill_parent"

>

\u0026lt;ScrollView android: layout_height = "fill_parent"

android: layout_width = " ; fill_parent>


\u0026lt;LinearLayout ; android: orientation = "vertical" android : layout_width = "fill_parent"
android: layout_height = "fill_parent"
>
; \u0026lt;ListView android: id = "@ + id / listav"
& # 160; android: layout_width = "fill_parent"

android: layout_height = " ; 300sp "

android: drawSelectorOnTop = false &
# 160; android: cacheColorHint = "# ff6a00"
android: divider = "ff8f40"

; android: dividerHeight = "2px"

/>
& # 160; \u0026lt;relative layout
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
& # 160; android: background = "676 767"
& # 160; android: orientation = "vertical">

\u0026lt;Button
& # 160; android: layout_width = "fill_parent"
; android: layout_height = "fill_parent"
android: id = "@ + id / btnGetMoreResults "
Android: padding = "10px"
; android: text = "Enter new data" />
\u0026lt;/ relative layout>
\u0026lt;relative layout
android: layout_width = "fill_parent"
& # 160; android: layout_height = "fill_parent"
android: background = "676 767"

android: orientation = "vertical">


& # 160; \u0026lt;Button
android: layout_width = "fill_parent"
& # 160; android: layout_height = "fill_parent"
& # 160; android: id = "@ + id/btnGetMoreResults1"
; android: padding = "10px"
& # 160; android: text = "Show detagli" />
\u0026lt;/ RelativeLayout>

; \u0026lt;/ LinearLayout>
\u0026lt;/ ScrollView>

\u0026lt;/ RelativeLayout>


-------------------
main.xml


------------------- \u0026lt;? xml version = "1.0" encoding = "UTF-8"?>
\u0026lt; table layout xmlns: android = "

http://schemas.android.com/apk/res/android"


android: layout_width = "fill_parent"

android: layout_height = "fill_parent"

android: stretch columns = " 1 "

>

\u0026lt;TableRow> ; \u0026lt;TextView Android:text="Nome:"/> \u0026lt;EditText android: id = "@ + id / name"

; android: hint = "Enter your name &

# 160; />
\u0026lt;/ TableRow> \u0026lt;TableRow> \u0026lt;TextView android:text="Indirizzo:"/>
\u0026lt;EditText android: id = "@ + id / via"
& # 160; android:hint="Scrivi il tuo indirizzo"
        />
    </TableRow>
        <TableRow>
        <TextView android:text="E-mail:"/>
        \u0026lt;EditText android: id = "@ + id / email"
& # 160; android: hint = "Enter your e-mail"
& # 160; />
\u0026lt;/ TableRow>
& # 160; \u0026lt;Button android: id = "@ + id / salva"
& # 160; android: layout_width = "fill_parent"
; android: layout_height = " ; wrap_content "
& # 160; android: text = "Salva"
; />
\u0026lt;Button android: id = "@ + id / impegni "
; android: layout_width = "fill_parent"
& # 160; android: layout_height = "wrap_content"
& # 160; android: text = "visualizza i dati"
& # 160; />
</TableLayout>

-------------------
Agenda.java
-------------------

/*
* To change this template, choose Tools *
* @author Lorenzo Millucci
*/
public class Agenda extends Activity {
    private final String DB_NAME="Studente.db";
    private SQLiteDatabase database = null;

    /** Called when the activity is first created. */

    @Override     public void onCreate(Bundle savedInstanceState)     {

         super.onCreate (savedInstanceState)

setContentView (R.layout.main)
creaDB ();
& # 160; creaTabella ();
Button save = (Button) findViewById (R. id.salva)

Button lista=(Button)findViewById(R.id.impegni);

        salva.setOnClickListener(salva1);

        lista.setOnClickListener(onLista);

    }

    private View.OnClickListener onLista=new View.OnClickListener(){
         public void onClick(View v){
             Intent i=new Intent(v.getContext(),Lista.class);
             startActivity(i);
             }
         };

    public void creaDB(){
        try{
            database=openOrCreateDatabase(DB_NAME,SQLiteDatabase.CREATE_IF_NECESSARY,null);
        }catch(SQLiteException e){
            e.printStackTrace();
        }
    }

    public void creaTabella(){
        try{
            if (database.isOpen()){
                         database.execSQL("CREATE TABLE IF NOT EXISTS dati (_id integer primary key autoincrement, nome varchar(20), via varchar(50), email varchar(50));");
            }
        }catch(SQLiteException e){
            e.printStackTrace();
        }
    }

    private View.OnClickListener salva1=new View.OnClickListener(){
         public void onClick (View v) {&

# 160; appunto1 = alt text (alt text) findViewById (R.id.nome)

; dove1 = edit text (alt text) findViewById (R.id.via)
& # 160; quando1 = edit text (alt text) findViewById (R.id.email)
& # 160; appunto1.getText String nome = (). toString ();
& # 160; String = dove1.getText by (). toString ();
& # 160; Quando1.getText String email = (). ToString ();
/ / dove1.setText ("");

& # 160; String insert = "INSERT INTO data (name, street name, email) values \u200b\u200b('" + name + "', '"+ +"','"+ via email +"');";

/ / ; String insert = "INSERT INTO data (name, street name, email) values \u200b\u200b('" + name +"',"+ via email +",'"+ +"');";
/ / , & # 160; String insert = "INSERT INTO vote (datavoto, mark, pattern, material, depth, name) values \u200b\u200b('" +
/ / datavoto +"',"+ vote +",'"+ +"','"+ plea on behalf +"','"+ Professor +"','"+ +"');";

try {
; database.execSQL (post);
& # 160;} catch (SQLiteException e) {

; e.printStackTrace();

             }
         }
     };

     @Override
     public void onDestroy() {
          super.onDestroy();
          database.close();
     }

}


-------------------
Lista.java
-------------------

package org.me.dbstudente;
import android.app.Activity;
import android.os.Bundle;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.content.Context;
import android.widget.*;
import android.view.View;

android.widget.ListView import, import

android.widget.AdapterView;
import android.database.Cursor;
import java.util.ArrayList;
import android.util.Log;
import android.content.Intent;
public class List
extends Activity {private final String DB_NAME = "Studente.db"

SQLiteDatabase private database = null;

private ListView votes
& # 160; ArrayList rows = new ArrayList \u0026lt;String> \u0026lt;String> ();
private String LVOT []={" 5 computer 10/02/2010 "" , 7 Italian 31/01/2010 "," 9 physical education 25/03/2010 "," 7 English 28/02/2010 "};
, / ** Called When the activity is first created. * / @ Override

public void onCreate (Bundle savedInstanceState)

    {

         super.onCreate(savedInstanceState);          setContentView(R.layout.lista);          creaDatabase();

         leggiTabellaVoto ();

votes = (ListView) findViewById (R.id.listav) ;
/ / By using setAdpater method in listview we add an string array list.
/ / log. ("votes =" + rating);
voti.setAdapter (new ArrayAdapter \u0026lt;String> (this, android.R.layout.simple_list_item_1, rows));
& # 160; Button enter = (Button) findViewById (R.id.btnGetMoreResults)
; inserisci.setOnClickListener (onInserisci);}

creaDatabase public void () {
try{          
                    database=openOrCreateDatabase(DB_NAME,SQLiteDatabase.CREATE_IF_NECESSARY, null);
          } Catch (SQLiteException e) {
& # 160; System.out.println ("did not create the database student") ;
e.printStackTrace ();}

& # 160;} public void
leggiTabellaVoto () {
& # 160; Cursor c = database.query ("dati", null, null, null, null, null, null, null);
& # 160; int numRows = c.getCount ();
& # 160; ; c.moveToFirst ();
& # 160; for (int i = 0; i < numRows; ++i) {
                              Riga r = new Riga();
                              r._id = c.getLong(0);
                              r.nome = c.getString(1);
                              r.via = c.getString(2);
                              r.email = c.getString(3);
                              String r.nome rr = + "" + r.via + "" + r.email;
& # 160; System.out.println (rr) ;
& # 160; righe.add (str);
& # 160; c.moveToNext ();
; & # 160;

}} class Line {
& # 160; public long _id;
; public String name;
public String street;
public String email;
     }
     private View.OnClickListener onInserisci=new View.OnClickListener(){
         public void onClick(View v) {
            Intent i = new Intent(v.getContext(), Agenda.class);
            startActivity(i);
         }
      };  
     @Override
     public void onDestroy() {
          super.onDestroy();
          database.close ();}

}













0 comments:

Post a Comment