android-cursoradapter

cursoradapter with different row layouts

£可爱£侵袭症+ 提交于 2019-11-27 10:39:42
I'm trying to create a custom cursoradapter that will use two different layouts depending on some data in the cursor. I keep reading about 'overriding getViewTypeCount() and getItemViewType()' to make this happen but I can't seem to figure out how to implement this.. This is my code for the bindView and new View methods: @Override public void bindView(View view, Context context, Cursor cursor) { TextView tView = (TextView) view.findViewById(R.id.TextView1); tView.setText("The text"); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { return mInflater.inflate(R

Converting an ArrayAdapter to CursorAdapter for use in a SearchView

若如初见. 提交于 2019-11-27 09:41:46
问题 How can I convert an ArrayAdapter<String> of static data into a CursorAdapter for using Suggestion Listener in SearchView ? I have constructed the ArrayAdapter<String> from static data ( allString ) ArrayAdapter<String> searchAdapter = new ArrayAdapter<String>(context, R.layout.listitem, allString); and I use it for an MultiAutoCompleteTextView which works fine in devices with API level less than 11 MultiAutoCompleteTextView findTextView.setAdapter(searchAdapter); However my target API is

Using CursorLoader with LoaderManager to retrieve images from android apps

风流意气都作罢 提交于 2019-11-27 08:18:28
问题 At the moment I’m using getContentResolver().query()/managedQuery() to get a cursor to retrieve images from the gallery app. Because the APIs I’m using are partly deprecated I wanted to use CursorLoader with LoaderManager. /** * Creates a cursor to access the content defined by the image uri for API * version 11 and newer. * * @return The created cursor. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private Cursor createCursorHoneycomb() { String[] projection = { MediaStore.Images.Media.DATA }

ORMLite with CursorAdapter in Android

跟風遠走 提交于 2019-11-27 02:44:45
问题 I am modifying my Android app to work with ORMLite, and it currently uses a number of CursorAdapters, which I quite want to keep in an attempt to minimise coding. I'm not 100% sure but t appears that when ORMLite creates an id field in the db, it always uses id , whereas CursorAdapter needs _id . It is possible to get round this using a query like the following: select id as _id ...... but the Dao.queryRaw() method returns a list, not a Cursor, so the way I have done it is to open another

How to remove a selected item from ListView using CursorAdapter

℡╲_俬逩灬. 提交于 2019-11-27 02:22:11
问题 I am using CursorAdapter and below is my adapter class. My list consists of two text views and one button on each row. Now, on click of the button I want to delete the selected item from the list as well as from the database. How can I get the id of the selected item from the database so that I can delete it and then notify the adapter (refresh the list). public class MyAdapter extends CursorAdapter { Cursor c; LayoutInflater inflater; Context context; private String TAG = getClass()

ListView using two cursoradapters?

て烟熏妆下的殇ゞ 提交于 2019-11-27 01:37:49
问题 I have some code which executes two queries against a database and returns two cursor objects. Is there any way that I can combine these two cursors so that all the ListView gets the data from both? 回答1: There's MergeCursor for that (if there's no way to join tables). 回答2: FYI - An example of using MergeCursor() c = Cursor containing Contacts columns from Contacts.CONTENT_URI private Cursor mergeCursorSubset(Cursor c) { int userMobile = ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE,

Android - Is ViewHolder pattern automatically implemented in CursorAdapter?

余生长醉 提交于 2019-11-27 00:54:13
问题 I always use ViewHolder pattern in my custom ArrayAdapter classes. However, in CursorAdapter the getView() method is not mandatory required to be overridden , but has the bindView and newView methods. My question is - does CursorAdapter re-uses views by internally implementing the ViewHolder pattern or it needs to be coded as we normally do in custom ArrayAdapter ? If it needs to be coded, what is the correct way to do it? Update I'm using android.support.v4.widget.CursorAdapter 回答1: My

MultiAutoCompleteTextView with contacts phone numbers

天大地大妈咪最大 提交于 2019-11-26 23:40:37
问题 I need to create a MultiAutoCompleteTextView with the phone numbers of the contacts on a user's device. What I need is similar to gmail; except with gmail email addresses are used. For the contacts, I have the following needs: each phone number must be an entry. So if John has 3 numbers (home, cell, work), they show as 3 entries each entry is searchable by phone number or by first/last name of person To create my adapter, I try to modify the one provided by Google but when I download the

Android: column '_id' does not exist

泪湿孤枕 提交于 2019-11-26 23:01:44
I am getting this error IllegalArgumentException: column '_id' does not exist When using a SimpleCursorAdapter to retrieve from my database, and the table does indeed have this _id column. Noticing this a common problem, I have tried to work around it given some of the solutions online but none of them work. This is my cursor query: SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.quoterow, myCursor, new String[]{"_id", "quote"}, new int[]{R.id.quote}); although I should mention the original did not include the _id column, I added this recently to try and solve the problem

SimpleCursorAdapter how to show an image?

故事扮演 提交于 2019-11-26 21:05:32
问题 I am making an android recipes application where i use a database. In database there is a column named" "images", where i store the name of the file of the picture of the recipe where i store at drawable folder. Now i want to make a List with the recipes, showing: 1) the Title of the recipe 2) a short description and 3) an image of the recipe To do that i use a Simplecursoradaptor. My problem is i can not show the image. I want to read the file name from the column "images" and then set the