• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps String problem (sqlite-query)

Ok, so you are using a toast to see what is in query1... and can I assume that query1 = "Test"?

where in the code are you calling the toast? Could the value of query1 have changed by the time the SQL is called?

Put your Toast.makeText(...) call right before
Code:
String keyword = "name1 LIKE '%"+query1+"%'";

Is it still the string you expect it to be?
 
Upvote 0
Seems like the Toast will not be shown, when I put it right before this line?! It all seems to be very slow....but it seems, you`re right.

I call ladeDaten(String query1) at the end of an onItemSelected (OnItemSelectedListener).
query1 = selecteditem...it looks like the value (query1) of item is still null?! ...any ideas or workaround for that?
As I said, I
 
Upvote 0
post your code for the selected item listener... maybe we can figure out what's wrong there.

I'm a Java developer for web applications (J2EE) but not really for Android, so I haven't really worked with Android event handlers a lot... But maybe an extra pair of eyes on your code is all we need here :)
 
Upvote 0
thanks :)
It`s just this:

public class MyOnItemSelectedListener1 implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
ladeDaten(parent.getItemAtPosition(pos).toString());
}

public void onNothingSelected(AdapterView<?> parent) {
// Do nothing. }}
}
}


This was the one with the toast:

public
class MyOnItemSelectedListener1 implements OnItemSelectedListener {
publicvoid onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(),
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show();
ladeDaten(parent.getItemAtPosition(pos).toString());
}

publicvoid onNothingSelected(AdapterView<?> parent) {
// Do nothing. }}
}
}

 
Upvote 0
I had to do some googling to figure out how the listener works. Seems to me you are missing a constructor for your listener class, where you would define the activity and adapter for your listener. See this example:

SpinnerActivity.java | Android Developers

Note the constructor:

Code:
        /**
         *  Constructor
         *  @param c - The activity that displays the Spinner.
         *  @param ad - The Adapter view that
         *    controls the Spinner.
         *  Instantiate a new listener object.
         */
        public myOnItemSelectedListener(Activity c, ArrayAdapter<CharSequence> ad) {

          this.mLocalContext = c;
          this.mLocalAdapter = ad;

        }


I don't see a constructor in your code block. Which means your listener is listening to nothing. That could explain the null :)
 
Upvote 0
Another problem, but I think, that`s my very small knowledge:

This one works:
Cursor klassenCursor = mDatenbank.query(
"Tabelle",
new String[] {
"feld1",
"feld2"
},
null, null, null, null,null );


this not:
String keyword = null;
Cursor klassenCursor = mDatenbank.query(
"Tabelle",
new String[] {
"feld1",
"feld2"
},
keyword, null, null, null,null );


Anyone, who could tell me why?

Thank you
 
Upvote 0
Oh, my third post in a row...I have solved the first issue:

onItemSelected will also be called at onCreate and that`s the problem...at least it seems, it`s okay now :)
I just use a boolean to check, if onItemSelected is called for the first time...

But I still don`t know, why I can`t set a string to null....
 
Upvote 0
btw, just to clarify, you shouldn't *technically* need a constructor for listener objects. Though the code and examples above make use of them.

Also @OP you should, when you get some time learn about binding your SQL queries

Also, the reason you cant convert null to a string is that you cant point to null.

To phrase it differently, you cant convert "nothing" into a string.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones