Reputation: 91
I have three classes,
Activity - displays the listview with my single_list_item.xml SQLiteOpenHelper - I'm currently running my queries here.
My activities and my SQLiteOpenHelper talks together well. However I'm not sure how to run a query from my third class
BaseAdapter - This one is not in my manifest, and with my current skills I can't access the db from this one - as I normally do from activity classes.
I want to hide a textview in my single_list_item.xml depending on the value from my query(the query only returns 0 or 1). I can easily hide it or show it statically by defining tv.setVisibility(View.GONE) etc. - But I want this one to be active or not depending of the usersettings.
Any help is greatly appreciated.
Upvotes: 0
Views: 737
Reputation: 5712
A common approach is to create a singleton, that is first initialized with a Context. That holds the SQLiteDatabase, and has all the data specific methods that you use from your application.
Thus, from your BaseAdapter, you call MyDBSingleton.getInstance().getData()
Be sure, that the singleton class keeps an ApplicationContext, and not a reference to an Activity/Service, as that could cause leaks...
Upvotes: 2