| |||||||
Das Thema "XML from WWW to SQLite" befindet sich unter Android App Entwicklung auf Android-Hilfe.de.
|
| | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| Neuer Benutzer Modell: Samsung Galaxy Tab Registriert seit: 01.06.2011
Beiträge: 1
Abgegebene Danke: 0
Erhielt 0 Danke für 0 Beiträge
| Dank an jeden, der seine Zeit für meine Frage "opfert"! Meine Aufgabe ist, eine XML von Internetadresse holen und mit SQLite DB abgleichen. Inhalt SQLite in ListActivity zur Auswahl anbieten und nach Userauswahl in extra Activity den Content aufbereitet anzeigen. SQLite DB Tabelle erstellen, Import, löschen hab ich schon geübt, abgleich fehlt mir. Aber wie importiere ich die XML in den raw Ordner und wie gleiche ich die die XML mit der SQLite ab? Für jeden "Schupps" dankbar! Sepp ![]() '###########Hab ein Beispiel gefunden............. gibt's besseres? import java.util.ArrayList; import java.util.HashMap; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import android.app.ListActivity; import android.content.ContentValues; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.util.Log; import android.widget.ListAdapter; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; public class Main extends ListActivity { //private static final String TAG = "com.pxr.tutorial.xmltest.Main"; private SQLiteDatabase database; //static final String ID="id"; static final String NAME="name"; static final String SCORE="score"; TextView error; // NEVER MORE DO THE SAME!!! // public void onCreate(SQLiteDatabase db) { // db.execSQL("CREATE TABLE constants (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, score INTEGER);"); // // ContentValues cv=new ContentValues(); // // //Test data // cv.put(NAME, "Ajay"); // cv.put(SCORE, "100"); // db.insert("constants", null, cv); // // } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listplaceholder); //IT'S OPENNING DATABASE IF DATABASE DOESYNT EXIST IT'S CREATING IT database = (new DatabaseHelper(this).getWritableDatabase()); //BETTER CREATE YOU OWN CLASS WITH FIELDS AND ACCESSORS ArrayList> mylist = new ArrayList>(); String xml = XMLfunctions.getXML(); Document doc = XMLfunctions.XMLfromString(xml); int numResults = XMLfunctions.numResults(doc); if((numResults map = new HashMap(); Element e = (Element)nodes.item(i); map.put("id", XMLfunctions.getValue(e, "id")); map.put("name", XMLfunctions.getValue(e, "name")); map.put("Score", XMLfunctions.getValue(e, "score")); mylist.add(map); } //READ SOMETING ABOUT ITERATORS AND COLLECTIONS IN JAVA for (int j = 0; j parent, View view, int position, long id) { @SuppressWarnings("unchecked") HashMap o = (HashMap) lv.getItemAtPosition(position); Toast.makeText(Main.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_LONG).show(); } });*/ } private void processAdd(String string, String string2, String string3) { // TODO Auto-generated method stub ContentValues values = new ContentValues(2); // values.put("id", string); values.put(DatabaseHelper.NAME, string2); values.put(DatabaseHelper.SCORE, string3); if(database!=null){ //INSERT IF DATABASE IS OPEN database.insert(DatabaseHelper.TABLE_NAME, null, values); // Log.i(TAG, "SAVED IN DATABASE"); }else{ //IF DATABASE IS CLOSED OPEN FIRST THAN INSERT database = (new DatabaseHelper(this).getWritableDatabase()); //Log.e(TAG, "DATABASE CLOSED, OPENNING..."); database.insert(DatabaseHelper.TABLE_NAME, null, values); //Log.i(TAG, "INSERTED INTO DATABASE"); } } @Override protected void onDestroy() { //ALWAYS CLOSE DATABASE IF YOU ARE FINISHING APPLICATION if(database!=null){ database.close(); } super.onDestroy(); } } Geändert von NewAndroider (03.06.2011 um 22:36 Uhr) |
| | |
![]() |
|
| Themen-Optionen | |
| Ansicht | |
| |
| ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| Frage zu www.teruten.com | grazer32 | Smalltalk und Offtopic | 1 | 31.01.2011 16:24 |
| www.cookmyrom.se | slimline | Root / Hacking / Modding für T-Mobile G2 Touch | 11 | 07.11.2010 10:20 |
| www.androidspin.com | sebi1986 | HTC Hero / T-Mobile G2 Touch Forum | 0 | 22.02.2010 15:42 |
| moblie www Sites umgehen? | Prayos | Android Allgemein | 1 | 24.11.2009 13:16 |
| XML/SQLite durchsuchen & UI Handling | TomS | Android App Entwicklung | 4 | 30.06.2009 15:27 |