Database

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Database

Postby dragon » Wed Jan 16, 2008 9:10 pm

Hello anyone,

i'am newbi coding android i'am coding in C++.
I have a main layout with several TextViews and a serch button at the bottom.
I have also a dialog with several spinners with items and a Ok button.
I chose in the spinners with items i want.
The items will be search in a database i created.
If the items are found i want to display the items in TextViews in my main layout.
But i don't see anything in my main layout.
Maybe i missing something!
I have no errors.

This is a part of my java code.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.     public void onCreate(Bundle icicle) {
  4.  
  5.         super.onCreate(icicle);
  6.  
  7.         setTheme(android.R.style.Theme_Dark);
  8.  
  9.         setContentView(R.layout.main);
  10.  
  11.        
  12.  
  13.         mattext=(EditText) this.findViewById(R.id.matet);
  14.  
  15.         koeltext=(TextView) this.findViewById(R.id.koelet);
  16.  
  17.         hardheidtext=(TextView) this.findViewById(R.id.hardheidet);
  18.  
  19.         snijtext=(TextView) this.findViewById(R.id.snijet);
  20.  
  21.         snedebtext=(TextView) this.findViewById(R.id.snedebet);
  22.  
  23.         snededtext=(TextView) this.findViewById(R.id.snededet);
  24.  
  25.         tandtext=(TextView) this.findViewById(R.id.tandet);
  26.  
  27.         voedtext=(TextView) this.findViewById(R.id.voedet);
  28.  
  29.         freesbtext=(TextView) this.findViewById(R.id.freesbet);
  30.  
  31.         diatext=(TextView) this.findViewById(R.id.diaet);
  32.  
  33.         trektext=(TextView) this.findViewById(R.id.treket);
  34.  
  35.         freesttext=(TextView) this.findViewById(R.id.freestet);
  36.  
  37.        
  38.  
  39.                 Button button =(Button) this.findViewById(R.id.zoek);
  40.  
  41.         button.setOnClickListener(new View.OnClickListener(){  
  42.  
  43.                 public void onClick(View arg0) {
  44.  
  45.                         zoek();
  46.  
  47.                    }
  48.  
  49.                 });
  50.  
  51.     }
  52.  
  53.  
  54.  
  55. public void zoek()
  56.  
  57.  {
  58.  
  59.          final Dialog freesDialog = new Dialog(this);
  60.  
  61.          freesDialog.setTitle("Gegevens");
  62.  
  63.          freesDialog.setContentView(R.layout.dialog);
  64.  
  65.          freesDialog.show();
  66.  
  67.          Button okbutton =(Button) freesDialog.findViewById(R.id.Ok);
  68.  
  69.          okbutton.setOnClickListener(new View.OnClickListener(){  
  70.  
  71.                 public void onClick(View view) {
  72.  
  73.                         freesDialog.dismiss();
  74.  
  75.                                    }
  76.  
  77.                 });
  78.  
  79.          String freest = null;
  80.  
  81.          
  82.  
  83.          Spinner matSpinner=(Spinner)freesDialog.findViewById(R.id.spinnermat);
  84.  
  85.          Spinner freestSpinner=(Spinner)freesDialog.findViewById(R.id.spinnerfrees);
  86.  
  87.          Spinner diaSpinner=(Spinner)freesDialog.findViewById(R.id.spinnerdia);
  88.  
  89.          Spinner tandSpinner=(Spinner)freesDialog.findViewById(R.id.spinnertand);
  90.  
  91.          Spinner freesbSpinner=(Spinner)freesDialog.findViewById(R.id.spinnerfreesb);
  92.  
  93.          
  94.  
  95.        
  96.  
  97.          ArrayAdapter<CharSequence> matadapter = ArrayAdapter.createFromResource(
  98.  
  99.              this, R.array.mat, android.R.layout.simple_spinner_item);
  100.  
  101.      matadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  102.  
  103.      matSpinner.setAdapter(matadapter);
  104.  
  105.      
  106.  
  107.  
  108.  
  109.          ArrayAdapter<CharSequence> freestadapter = ArrayAdapter.createFromResource(
  110.  
  111.              this, R.array.frees, android.R.layout.simple_spinner_item);
  112.  
  113.      freestadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  114.  
  115.      freestSpinner.setAdapter(freestadapter);
  116.  
  117.      
  118.  
  119.      ArrayAdapter<CharSequence> diamadapter = ArrayAdapter.createFromResource(
  120.  
  121.              this, R.array.dia, android.R.layout.simple_spinner_item);
  122.  
  123.      diamadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  124.  
  125.      diaSpinner.setAdapter(diamadapter);
  126.  
  127.      
  128.  
  129.      ArrayAdapter<CharSequence> tandadapter = ArrayAdapter.createFromResource(
  130.  
  131.              this, R.array.tand, android.R.layout.simple_spinner_item);
  132.  
  133.      tandadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  134.  
  135.      tandSpinner.setAdapter(tandadapter);
  136.  
  137.      
  138.  
  139.      ArrayAdapter<CharSequence> bewerkadapter = ArrayAdapter.createFromResource(
  140.  
  141.              this, R.array.bewerk, android.R.layout.simple_spinner_item);
  142.  
  143.      bewerkadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  144.  
  145.      freesbSpinner.setAdapter(bewerkadapter);
  146.  
  147.      
  148.  
  149.        
  150.  
  151.          
  152.  
  153.                 SQLiteDatabase myDB = null;
  154.  
  155.                 try {
  156.  
  157.                         this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
  158.  
  159.                         myDB = this.openDatabase(MY_DATABASE_NAME, null);
  160.  
  161.                         myDB.execSQL("CREATE TABLE IF NOT EXITS "
  162.  
  163.                                         + MY_DATABASE_TABLE
  164.  
  165.                                         + "(freestype VARCHAR, freesdiameter VARCHAR, aantaltanden VARCHAR, "
  166.  
  167.                                         + "materiaal VARCHAR, hardheid VARCHAR, treksterkte VARCHAR,"
  168.  
  169.                                         + "koeling VARCHAR, freesbewerking VARCHAR, snijsnelheid VARCHAR,"
  170.  
  171.                                         + "snedediepte VARCHAR, snedebreedte VARCHAR, voedingpertand VARCHAR);");
  172.  
  173.                         myDB.execSQL("INSERT INTO "
  174.  
  175.                                         + MY_DATABASE_TABLE
  176.  
  177.                                         + "(freestype, freesdiameter, aantaltanden, materiaal, hardheid, treksterkte,"
  178.  
  179.                                         + "koeling, freesbewerking snijsnelheid, snedediepte, snedebreedte, voedingpertand)"
  180.  
  181.                                         + "VALUES('ECP', '12', '4', 'C45', '180', '350-800'', 'Nee', 'Contour frezen', '160', '16', '4', '0.05');");
  182.  
  183.                         myDB.execSQL("INSERT INTO "
  184.  
  185.                                         + MY_DATABASE_TABLE
  186.  
  187.                                         + "(freestype, freesdiameter, aantaltanden, materiaal, hardheid, treksterkte,"
  188.  
  189.                                         + "koeling, freesbewerking snijsnelheid, snedediepte, snedebreedte, voedingpertand)"
  190.  
  191.                                         + "VALUES('ERF', '16', '4', 'C60', '180', '350-800'', 'Nee', 'Gleuf frezen', '200', '20', '4', '0.05');");
  192.  
  193.                        
  194.  
  195.                         Cursor c = myDB.query("SELECT + FROM + MY_DATABASE_TABLE + WHERE freestype='" + freestSpinner.getSelectedItemIndex() + "'AND freesdiameter='" + diaSpinner.getSelectedItemIndex() + "'AND aantaltanden='" + tandSpinner.getSelectedItemIndex() + "'AND materiaal='" + matSpinner.getSelectedItemIndex() + "'AND  freesbewerking='" + freesbSpinner.getSelectedItemIndex() + "';",null);  // Maybe the select statement is wrong?
  196.  
  197.                        
  198.  
  199.                                         int freestypeNameColumn = c.getColumnIndex("freestype");
  200.  
  201.                                         int freesdiameterNameColumn = c.getColumnIndex("freesdiameter");
  202.  
  203.                                         int aantaltandenNameColumn = c.getColumnIndex("aantaltanden");
  204.  
  205.                                         int materiaalNameColumn = c.getColumnIndex("materiaal");
  206.  
  207.                                         int hardheidNameColumn = c.getColumnIndex("hardheid");
  208.  
  209.                                         int treksterkteNameColumn = c.getColumnIndex("treksterkte");
  210.  
  211.                                         int koelingNameColumn = c.getColumnIndex("koeling");
  212.  
  213.                                         int freesbewerkingNameColumn = c.getColumnIndex("freesbewerking");
  214.  
  215.                                         int snijsnelheidNameColumn = c.getColumnIndex("snijsnelheid");
  216.  
  217.                                         int snedediepteNameColumn = c.getColumnIndex("snedediepte");
  218.  
  219.                                         int snedebreedteNameColumn = c.getColumnIndex("snedebreedte");
  220.  
  221.                                         int voedingpertandNameColumn = c.getColumnIndex("voedingpertand");
  222.  
  223.                                        
  224.  
  225.                         c.first();
  226.  
  227.                                 do {
  228.  
  229.                                 freest = c.getString(freestypeNameColumn);
  230.  
  231.                                 freesttext.setText(freest);
  232.  
  233.                                 String freesd = c.getString(freesdiameterNameColumn);
  234.  
  235.                                 diatext.setText(freesd);
  236.  
  237.                                 String aantal = c.getString(aantaltandenNameColumn);
  238.  
  239.                                 tandtext.setText(aantal);
  240.  
  241.                                 String mat= c.getString(materiaalNameColumn);
  242.  
  243.                                 mattext.setText(mat);
  244.  
  245.                                 String trek = c.getString(treksterkteNameColumn);
  246.  
  247.                                 trektext.setText(trek);
  248.  
  249.                                 String hardh = c.getString(hardheidNameColumn);
  250.  
  251.                                 hardheidtext.setText(hardh);
  252.  
  253.                                 String koel = c.getString(koelingNameColumn);
  254.  
  255.                                 koeltext.setText(koel);
  256.  
  257.                                 String freesb = c.getString(freesbewerkingNameColumn);
  258.  
  259.                                 freesbtext.setText(freesb);
  260.  
  261.                                 String snijsnel = c.getString(snijsnelheidNameColumn);
  262.  
  263.                                 snijtext.setText(snijsnel);
  264.  
  265.                                 String sneded = c.getString(snedediepteNameColumn);
  266.  
  267.                                 snededtext.setText(sneded);
  268.  
  269.                                 String snedeb = c.getString(snedebreedteNameColumn);
  270.  
  271.                                 snedebtext.setText(snedeb);
  272.  
  273.                                 String voeding = c.getString(voedingpertandNameColumn);
  274.  
  275.                                 voedtext.setText(voeding);
  276.  
  277.                                 } while(c.next());      
  278.  
  279.  
  280.  
  281.         }catch (FileNotFoundException e)  {
  282.  
  283.         } finally {
  284.  
  285.                 if (myDB != null)
  286.  
  287.                         myDB.close();
  288.  
  289.         }
  290.  
  291.  }
  292.  
  293. }
Parsed in 0.058 seconds, using GeSHi 1.0.8.4
dragon
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jan 16, 2008 7:36 pm

Top

Postby plusminus » Wed Jan 16, 2008 11:32 pm

Hello dragon,

[Edit]New Answer[/Edit]
Now I see your bug, it is the statement:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Cursor c = myDB.query("SELECT + FROM + MY_DATABASE_TABLE + WHERE ...
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

should be like:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Cursor c = myDB.query("SELECT FROM " + MY_DATABASE_TABLE + "WHERE ...
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


I would have assumed that an Runtime-Exception would have occured, but as you said non occured.

Let us know if this helped you. :)

[Edit]Old Answer[/Edit]
did you ensure with debugging, that your code reaches this part :?: (note that you override the text that would be displayed on every cycle of the do-while loop :!: )
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                c.first();
  2.                     do {
  3.                     freest = c.getString(freestypeNameColumn);
  4.                     freesttext.setText(freest);
  5.                          String freesd = c.getString(freesdiameterNameColumn);
  6.                     diatext.setText(freesd);
  7.                     String aantal = c.getString(aantaltandenNameColumn);
  8.                     tandtext.setText(aantal);
  9.                    
  10.                     //...
  11.  
  12.                     String snedeb = c.getString(snedebreedteNameColumn);
  13.                     snedebtext.setText(snedeb);
  14.                     String voeding = c.getString(voedingpertandNameColumn);
  15.                     voedtext.setText(voeding);
  16.                        } while(c.next());
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Place some Debug-lines within, like:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                c.first();
  2.                     do {
  3.                            freest = c.getString(freestypeNameColumn);
  4.                            freesttext.setText(freest);
  5.                            // Do Debug
  6.                            Log.d("DEBUGTAG", "Called 'freesttext.setText(freest);'"
  7.                                                       + " with freest='" + freest + "'.");
  8.  
  9.                            //...
  10.  
  11.                     } while(c.next());
Parsed in 0.038 seconds, using GeSHi 1.0.8.4



Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby dragon » Thu Jan 17, 2008 6:08 pm

Hello,

I have changed the Select statement in the query.
I have also insert debug lines.
I have no errors butt still i don't see anything in main layout.

This part off my main.xml
I use RelativeLayout.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:layout_width="fill_parent"
  7.  
  8.    android:layout_height="fill_parent"
  9.  
  10.    >
  11.  
  12.    
  13.  
  14.                         <TextView id="@+id/gegevenslabel"
  15.  
  16.                         android:layout_width="fill_parent"
  17.  
  18.                         android:layout_height="wrap_content"
  19.  
  20.                         android:textAlign="center"
  21.  
  22.                         android:textColor="@drawable/yellow"
  23.  
  24.                         android:padding="7px"
  25.  
  26.                         android:text="Frees gegevens"/>
  27.  
  28.                         <TextView id="@+id/freestlabel"
  29.  
  30.                         android:layout_width="fill_parent"
  31.  
  32.                         android:layout_height="wrap_content"
  33.  
  34.                         android:textColor="@drawable/white"
  35.  
  36.                         android:layout_below="@id/gegevenslabel"
  37.  
  38.                         android:paddingBottom="2px"
  39.  
  40.                         android:text="Freestype:" />
  41.  
  42.                         <TextView id="@+id/freestet"  // This one off 7 Textviews.
  43.  
  44.                         android:layout_height="23px"
  45.  
  46.                         android:layout_width="120px"
  47.  
  48.                         android:textSize="12px"
  49.  
  50.                         android:layout_below="@id/gegevenslabel"
  51.  
  52.                         android:layout_alignRight="@id/freestlabel"/>
  53.  
  54.                        
  55.  
  56.  
  57.  
  58.                         <TextView id="@+id/dialabel"
  59.  
  60.                         android:layout_width="fill_parent"
  61.  
  62.                         android:layout_height="wrap_content"
  63.  
  64.                         android:textColor="@drawable/white"
  65.  
  66.                         android:layout_below="@id/freestlabel"
  67.  
  68.                         android:paddingBottom="2px"
  69.  
  70.                         android:text="Frees diameter (D):" />
  71.  
  72.                         <TextView id="@+id/diaet"  // This one TextView i used
  73.  
  74.                         android:layout_height="22px"
  75.  
  76.                         android:layout_width="40px"
  77.  
  78.                         android:textSize="12px"
  79.  
  80.                         android:layout_below="@id/freestet"
  81.  
  82.                         android:layout_alignRight="@id/dialabel"/>
  83.  
  84.                        
  85.  
  86.                         <TextView id="@+id/tandlabel"
  87.  
  88.                         android:layout_width="fill_parent"
  89.  
  90.                         android:layout_height="wrap_content"
  91.  
  92.                         android:textColor="@drawable/white"
  93.  
  94.                         android:layout_below="@id/dialabel"
  95.  
  96.                         android:paddingBottom="2px"
  97.  
  98.                         android:text="Aantal tanden (z):" />
  99.  
  100.                         <TextView id="@+id/tandet" //This one off 7 TextViews
  101.  
  102.                         android:layout_height="22px"
  103.  
  104.                         android:layout_width="40px"
  105.  
  106.                         android:textSize="12px"
  107.  
  108.                         android:layout_below="@id/diaet"
  109.  
  110.                         android:layout_alignRight="@id/dialabel"/>
Parsed in 0.008 seconds, using GeSHi 1.0.8.4


Any suggestions.
Thanks in advance.
dragon
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jan 16, 2008 7:36 pm

Postby plusminus » Thu Jan 17, 2008 9:12 pm

Hello dragon,

my fault, there is another(actually two) error in the sql-statement, you need to specify the columns you want to retrieve (or " * " for all):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Cursor c = myDB.query("SELECT FROM " + MY_DATABASE_TABLE + "WHERE ...
  2.  
  3. // Change to ( Added " * ", and space before "WHERE" )
  4.  
  5. Cursor c = myDB.query("SELECT * FROM " + MY_DATABASE_TABLE + " WHERE ...
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Could be a good reason for the fact nothing is being displayed.

If it still doesn't work, remove the "WHERE ... = ..."-Clause from your statement, to further simplify it.

Let us know if you get this thing solved.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby dragon » Sun Jan 20, 2008 7:19 pm

I think i found something strange with the creation off a database.

I have sample databasework that works fine.
If i go to the commandline adb shell and cd to the database off databasework that is not a problem.
if i type ls i see this line.
drwxrwx--x app_12 2008-01-18 databases // that is Ok i can cd to database.

But if i use my app frezen in commandline adb shell.
I cd/data/data/com.google.android.frezen
If i type ls i see this line.
-rw-r--r-- root 0 2008-01-18 databases // that is not Ok i can't cd to databases
I think my app can't reach the database because is not directory and not exutable and don't have app_number.
This is a strange behavior because the Java coding is correct.

Any idea

Thanks in advance
dragon
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jan 16, 2008 7:36 pm

Postby cabernet1976 » Fri Jan 25, 2008 2:37 am

Hi dragon,

If your program make some exception and cannot operate database again (i.e. cannot open database or insert record), just try to use adb to rmdir whole of the directory: /data/data/your-package/, then run the program again.

Good luck.
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Top

Postby dragon » Tue Jan 29, 2008 6:28 pm

I solved the problem with the database i can use the database.
But still i have a problem with my spinners.
I use my spinners in a dialog to find in the database the items and display them in the main layout

code snippet
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. SQLiteDatabase myDB = null;
  2.  
  3.                 try {
  4.  
  5.                         /* Create the Database (no Errors if it already exists) */
  6.  
  7.                         this.createDatabase(MY_DATABASE_NAME, 1, 0, null);
  8.  
  9.                         /* Open the DB and remember it */
  10.  
  11.                         myDB = this.openDatabase(MY_DATABASE_NAME, null);
  12.  
  13.                        
  14.  
  15.                         myDB.execSQL("CREATE TABLE IF NOT EXISTS "
  16.  
  17.                                         + MY_DATABASE_TABLE
  18.  
  19.                                         + "(freestype VARCHAR, freesdiameter VARCHAR, aantaltanden VARCHAR, "
  20.  
  21.                                         + "materiaal VARCHAR, hardheid VARCHAR, treksterkte VARCHAR,"
  22.  
  23.                                         + "koeling VARCHAR, freesbewerking VARCHAR, snijsnelheid VARCHAR,"
  24.  
  25.                                         + "snedediepte VARCHAR, snedebreedte VARCHAR, voedingpertand VARCHAR);");
  26.  
  27.                         myDB.execSQL("INSERT INTO "
  28.  
  29.                                         + MY_DATABASE_TABLE
  30.  
  31.                                         + "(freestype, freesdiameter, aantaltanden, materiaal, hardheid, treksterkte,"
  32.  
  33.                                         + "koeling, freesbewerking, snijsnelheid, snedediepte, snedebreedte, voedingpertand)"
  34.  
  35.                                         + "VALUES('ECP', '12', '4', 'C45', '180', '350-800', 'Nee', 'Contour frezen', '160', '16', '4', '0.05');");
  36.  
  37.                         myDB.execSQL("INSERT INTO "
  38.  
  39.                                         + MY_DATABASE_TABLE
  40.  
  41.                                         + "(freestype, freesdiameter, aantaltanden, materiaal, hardheid, treksterkte,"
  42.  
  43.                                         + "koeling, freesbewerking, snijsnelheid, snedediepte, snedebreedte, voedingpertand)"
  44.  
  45.                                         + "VALUES('ERF', '16', '4', 'C60', '180', '350-800', 'Nee', 'Gleuf frezen', '160', '16', '4', '0.07');");
  46.  
  47.                         myDB.execSQL("INSERT INTO "
  48.  
  49.                                         + MY_DATABASE_TABLE
  50.  
  51.                                         + "(freestype, freesdiameter, aantaltanden, materiaal, hardheid, treksterkte,"
  52.  
  53.                                         + "koeling, freesbewerking, snijsnelheid, snedediepte, snedebreedte, voedingpertand)"
  54.  
  55.                                         + "VALUES('ERF', '16', '4', 'St37-2', '180', '350-800', 'Nee', 'Contour frezen', '160', '16', '4', '0.07');");
  56.  
  57.                        
  58.  
  59.                         Cursor c = myDB.query("SELECT * FROM " + MY_DATABASE_TABLE + " WHERE materiaal='" + matSpinner.getSelectedItemIndex()+ "';" ,null);    
  60.  
  61.                
  62.  
  63.  
  64.  
  65.                         /* Get the indices of the Columns we will need */
  66.  
  67.                         int freestypeNameColumn = c.getColumnIndex("freestype");
  68.  
  69.                         int freesdiameterNameColumn = c.getColumnIndex("freesdiameter");
  70.  
  71.                         int aantaltandenNameColumn = c.getColumnIndex("aantaltanden");
  72.  
  73.                         int materiaalNameColumn = c.getColumnIndex("materiaal");
  74.  
  75.                         int hardheidNameColumn = c.getColumnIndex("hardheid");
  76.  
  77.                         int treksterkteNameColumn = c.getColumnIndex("treksterkte");
  78.  
  79.                         int koelingNameColumn = c.getColumnIndex("koeling");
  80.  
  81.                         int freesbewerkingNameColumn = c.getColumnIndex("freesbewerking");
  82.  
  83.                         int snijsnelheidNameColumn = c.getColumnIndex("snijsnelheid");
  84.  
  85.                         int snedediepteNameColumn = c.getColumnIndex("snedediepte");
  86.  
  87.                         int snedebreedteNameColumn = c.getColumnIndex("snedebreedte");
  88.  
  89.                         int voedingpertandNameColumn = c.getColumnIndex("voedingpertand");
  90.  
  91.                
  92.  
  93.                         String freest = null;
  94.  
  95.                                 /* Check if at least one Result was returned. */
  96.  
  97.                                 if (c.first()) {
  98.  
  99.                                         /* Loop through all Results */
  100.  
  101.                                         if (c.next())
  102.  
  103.                                                 freest = c.getString(freestypeNameColumn);
  104.  
  105.                                                 freesttext.setText(freest);
  106.  
  107.                                                 String freesd = c.getString(freesdiameterNameColumn);
  108.  
  109.                                         diatext.setText(freesd);
  110.  
  111.                                         String aantal = c.getString(aantaltandenNameColumn);
  112.  
  113.                                         tandtext.setText(aantal);
  114.  
  115.                                         String mat= c.getString(materiaalNameColumn);
  116.  
  117.                                         mattext.setText(mat);
  118.  
  119.                                         String hardh = c.getString(hardheidNameColumn);
  120.  
  121.                                         hardheidtext.setText(hardh);
  122.  
  123.                                         String trek = c.getString(treksterkteNameColumn);
  124.  
  125.                                         trektext.setText(trek);
  126.  
  127.                                         String koel = c.getString(koelingNameColumn);
  128.  
  129.                                         koeltext.setText(koel);
  130.  
  131.                                         String freesb = c.getString(freesbewerkingNameColumn);
  132.  
  133.                                         freesbtext.setText(freesb);    
  134.  
  135.                                         String snijsnel = c.getString(snijsnelheidNameColumn);
  136.  
  137.                                         snijtext.setText(snijsnel);
  138.  
  139.                                         String sneded = c.getString(snedediepteNameColumn);
  140.  
  141.                                         snededtext.setText(sneded);
  142.  
  143.                                         String snedeb = c.getString(snedebreedteNameColumn);
  144.  
  145.                                         snedebtext.setText(snedeb);
  146.  
  147.                                         String voeding = c.getString(voedingpertandNameColumn);
  148.  
  149.                                         voedtext.setText(voeding);
  150.  
  151.                                         }
Parsed in 0.051 seconds, using GeSHi 1.0.8.4


if i run this application then its popup the dialog with the spinners.
if i choose a item i wnat look for in the database then nothing showing up in the main layout.
If i look in the adb logcat then following line is showing:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. W/SQLiteDirectCursorDriver( 548); Found Sql string that ends in ; --SELECT * FROM test WHERE materiaal='0'
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

I have in my matSpinner severals items, "C45", "C60", "St37-2"etc..
Is it possibly that i missing something.

Thanks in advance.
dragon
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jan 16, 2008 7:36 pm

Postby plusminus » Tue Jan 29, 2008 8:23 pm

Hello dragon,

you are using matSpinner.getSelectedItemIndex() (what returns just the index of the selected item) in the WHERE-Clause. You should probably be using matSpinner.getSelectedItem().toString() instead.

Perhaps this solves your problem. :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby dragon » Fri Feb 01, 2008 4:45 pm

Ok it works for a part of the application.
I have only one question about selecting item in the spinner.
I have read several threads about onItemSelecetListener in this forum.
Now i only see the first item in de spinner, i have read you must use onItemSelectListener to get another item for selecting.

I use now on this moment

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void zoek()
  2.  
  3. {
  4.  
  5.          final Dialog freesDialog = new Dialog(this);
  6.  
  7.          freesDialog.setTitle("Gegevens");
  8.  
  9.          freesDialog.setContentView(R.layout.dialog);
  10.  
  11.          freesDialog.show();
  12.  
  13.          Button okbutton =(Button) freesDialog.findViewById(R.id.Ok);
  14.  
  15.          okbutton.setOnClickListener(new View.OnClickListener(){  
  16.  
  17.                 public void onClick(View view) {
  18.  
  19.                         freesDialog.dismiss();
  20.  
  21.                                    }
  22.  
  23.                 });
  24.  
  25.          
  26.  
  27.          Spinner freestSpinner=(Spinner)freesDialog.findViewById(R.id.spinnerfrees);
  28.  
  29.          ArrayAdapter<CharSequence> freestadapter = ArrayAdapter.createFromResource(
  30.  
  31.                             this, R.array.frees, android.R.layout.simple_spinner_item);
  32.  
  33.         freestadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  34.  
  35.         freestSpinner.setAdapter(freestadapter);
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Can i change that in this?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void zoek()
  2.  
  3. {
  4.  
  5.          final Dialog freesDialog = new Dialog(this);
  6.  
  7.          freesDialog.setTitle("Gegevens");
  8.  
  9.          freesDialog.setContentView(R.layout.dialog);
  10.  
  11.          freesDialog.show();
  12.  
  13.          Button okbutton =(Button) freesDialog.findViewById(R.id.Ok);
  14.  
  15.          okbutton.setOnClickListener(new View.OnClickListener(){  
  16.  
  17.                 public void onClick(View view) {
  18.  
  19.                         freesDialog.dismiss();
  20.  
  21.                                    }
  22.  
  23.                 });
  24.  
  25.          
  26.  
  27.                 Spinner freestSpinner=(Spinner)freesDialog.findViewById(R.id.spinnerfrees);
  28.  
  29.                 freestSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
  30.  
  31.                         @Override
  32.  
  33.                         public void onItemSelected(AdapterView parent, View v, int position, long id) {
  34.  
  35.                                 ArrayAdapter<CharSequence> freestadapter = ArrayAdapter.createFromResource(
  36.  
  37.                                                 this, R.array.frees, android.R.layout.simple_spinner_item);
  38.  
  39.                                 freestadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  40.  
  41.                                 freestSpinner.setAdapter(freestadapter);
  42.  
  43.                         }
  44.  
  45.                 }); //  <-This gives my a error
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


I now there something wrong with this code but i ám newbe android.

Thanks in advance.
dragon
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jan 16, 2008 7:36 pm

Postby plusminus » Fri Feb 01, 2008 6:53 pm

Hello

your error is... right :?: :
Cannot refer to a non-final variable freestSpinner inside an inner class defined in a different method


Just place freestSpinner as a class variable instead of using is as a local variable.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby dragon » Sat Feb 02, 2008 3:48 pm

Can you give me a litle example code.
Ihave still error's

Thaks in advance.
dragon
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jan 16, 2008 7:36 pm

Postby plusminus » Sat Feb 02, 2008 4:03 pm

Hello dragon,

i do not know your code, so how to help :?: I also do not know what the error message is. :(

two post before I was speaking of sth like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. class YourClass{
  3.  
  4.  
  5.  
  6. private Spinner freestSpinner;
  7.  
  8.  
  9.  
  10. public void zoek(){
  11.  
  12.       final Dialog freesDialog = new Dialog(this);
  13.  
  14.       freesDialog.setTitle("Gegevens");
  15.  
  16.       freesDialog.setContentView(R.layout.dialog);
  17.  
  18.       freesDialog.show();
  19.  
  20.       Button okbutton =(Button) freesDialog.findViewById(R.id.Ok);
  21.  
  22.       okbutton.setOnClickListener(new View.OnClickListener(){  
  23.  
  24.                public void onClick(View view) {
  25.  
  26.                     freesDialog.dismiss();
  27.  
  28.                             }
  29.  
  30.                });
  31.  
  32.      
  33.  
  34.           freestSpinner=(Spinner)freesDialog.findViewById(R.id.spinnerfrees);
  35.  
  36.           freestSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
  37.  
  38.                @Override
  39.  
  40.                public void onItemSelected(AdapterView parent, View v, int position, long id) {
  41.  
  42.                     ArrayAdapter<CharSequence> freestadapter = ArrayAdapter.createFromResource(
  43.  
  44.                               this, R.array.frees, android.R.layout.simple_spinner_item);
  45.  
  46.                     freestadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  47.  
  48.                     freestSpinner.setAdapter(freestadapter);
  49.  
  50.                }
  51.  
  52.           });
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


without more information I cannot help further.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby dragon » Sat Feb 02, 2008 4:44 pm

Hello,

Here are the error's i have comment the errors.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. class SpinnerBox{
  2.  
  3.  
  4.  
  5.                  private Spinner freestSpinner;
  6.  
  7.  
  8.  
  9.                  public void zoek(){
  10.  
  11.                        final Dialog freesDialog = new Dialog(this); // Give a error.
  12.  
  13.                        freesDialog.setTitle("Gegevens");
  14.  
  15.                        freesDialog.setContentView(R.layout.dialog);
  16.  
  17.                        freesDialog.show();
  18.  
  19.                        Button okbutton =(Button) freesDialog.findViewById(R.id.Ok);
  20.  
  21.                        okbutton.setOnClickListener(new View.OnClickListener(){  
  22.  
  23.                                 public void onClick(View view) {
  24.  
  25.                                      freesDialog.dismiss();
  26.  
  27.                                              }
  28.  
  29.                                 });
  30.  
  31.                      
  32.  
  33.                            freestSpinner=(Spinner)freesDialog.findViewById(R.id.spinnerfrees);
  34.  
  35.                            freestSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){ // Give a error.
  36.  
  37.                                 @Override
  38.  
  39.                                 public void onItemSelected(AdapterView parent, View v, int position, long id) {  // Give a error.
  40.  
  41.                                      ArrayAdapter<CharSequence> freestadapter = ArrayAdapter.createFromResource( // Give a error.
  42.  
  43.                                                this, R.array.frees, android.R.layout.simple_spinner_item);
  44.  
  45.                                      freestadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  46.  
  47.                                      freestSpinner.setAdapter(freestadapter);
  48.  
  49.                                 }
  50.  
  51.                            });
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


Thaks in advance.
dragon
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jan 16, 2008 7:36 pm

Postby plusminus » Sat Feb 02, 2008 10:30 pm

Hello dragon,

you need to be extending "Activity" (like JFrame in Swing).
Then you can use functions like findViewByID(...).

Every Activity look principally similar to this one:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.anddev.android.Hello_Android;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5.  
  6. public class Hello_Android extends Activity {
  7.     /** Called when the activity is first created. */
  8.     @Override
  9.     public void onCreate(Bundle icicle) {
  10.         super.onCreate(icicle);
  11.         // Make Android use the main.xml-layout-file.  
  12.         this.setContentView(R.layout.main);
  13.     }
  14. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


If you want to create a Dialog-Style window like this one:
Image

you need to create a normal Activity and add this line in onCreate:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.setTheme(android.R.style.Theme_Dialog);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest