Android :: CursorAdapter Calling BindView On Every Item

Oct 4, 2010

I was using some of the code from DeskClock and found that when I tried to modify the CursorAdapter that newView was getting called for each item. (I actually wanted to add a divider and it seems like adding the dividers separately is better than adding them into a single listView)

If I have 3 items I get the following behavior:

CODE:.............

I would've expected newView/bindView to be called once per cursor item. But, that doesn't seem to be the case. This was kind of a problem for me because I wanted to select the appropriate view depending on the cursor data, but since bindView could be called before newView that doesn't work.

Is this some odd recycler behavior (or somehow normal/expected)? Or is there something broken with the code (I removed everything except the ListView and it's still doing this)? I'm not quite sure why you would try to bind views that haven't been created, and why newView gets called on the first item twice.

If someone has an easy way of adding dividers to ListViews I'd love to know. I was going to try to dig through the contacts example to see how they did it there if not.

In case anyone's wondering MergeAdapter was neat to mess around with and try (I'll use it in some other situations). But, I did just end up writing a single adapter that handles multiple views. It computes the type of each item (which is small), stores it in a map, initializes it at adapter creation, and updates it in notifyDataSetChanged.

Then you just need to have getViewTypeCount() return the number of possible views. And getItemViewType to return the type from the map (which is 0 based, so 0-getViewTypeCount()). If you can compute your type from the position you don't need the map, but doing this on the fly wasn't possible so I just pre/recompute when needed.

Android :: CursorAdapter calling bindView on every item


Android :: GetView Vs BindView In A Custom CursorAdapter

Aug 20, 2010

I'm watching this video http://www.youtube.com/watch?v=N6YdwzAvwOA and Romain Guy is showing how to make more efficient UI adapter code using the getView() method. Does this apply to CursorAdapters as well? I'm currently using bindView() and newView() for my custom cursor adapters. Should I be using getView instead?

View 1 Replies View Related

Android :: SimpleCursorAdapter.bindView - And Row Views

Oct 22, 2009

I have a problem with bindView() that has me puzzled. I am using it to customize each row, including setting icons, coloring the background and setting up listeners for buttons. It mostly works as expected, but not quite.

When I fill the ListView with SimpleCursorAdapter, I get multiple calls to bindView() for position 0, but only 1 call for the other rows. The problem is that when all is said and done, I have 2 rows (LinearLayout) created for position 0. Here is a sample log extract:

CODE:........

I use a view holder class to hold the view, position and other data so that when a button is clicked, I can retrieve the holder with view.getParent.getTag(). This all works fine. The problem is that there are two views for position 0, but it's the first one in the above logcat that seems to be displayed. My code which acts on the rows when a button is clicked (especially setting background color) does not reliably hit the position 0 row that is actually displayed.

I can see what's happening but I am at a loss about what to do about it. Why are two view created for position 0? Is it something that I can control? How? If not, how should I deal with it so that the results when I modify the views are predictable?

View 5 Replies View Related

Android :: Using BindView To Customize ListView

Feb 7, 2009

In all the examples I've found to manipulate each view in a ListView, the method always seems to be getView(). But these were never Adapters backed by a cursor. I decided to try bindView() within a SimpleCursorAdapter, and so far it works very nicely, especially with the cursor all set up for my use.

My question is, is this usage good practice, and could I run into a problem in future? My question may be dumb but I just couldn't find a good example code snippet that uses a cursor.

View 2 Replies View Related

Android :: Overrided SimpleCursorAdapter BindView Not Being Called

Mar 19, 2010

The problem is as follows: - My app is deriving from TabActivity that has 3 tabs - Each tab has a ListView - Tab1 is populated by an adapter that inherit SimpleCursorAdapter and overrided the bindView() method. This tab is displaying correctly. - Tab 2 is also populated by another adatper that inherit SimpleCursorAdapter and overrided the bindView() method. For some reason that I don't understand, the overrided bindView() is not being called. Thus the tab is not displaying correctly.

Here's my code fragment:

CODE:...........................

View 3 Replies View Related

Android :: Multiple Calls To SimpleCursorAdapater#bindView

Oct 3, 2010

I am using setViewValue method of ShowViewBinder to access image inside row of listView. The idea is to load image from internet and display it inside row of listView.

To load image, I am starting new image loader thread, but what I discovered when debugging this code, for each row I am actually starting 3 or 4 threads. I don't understand why. The code in if (columnIndex == ...) is executing more than once.

My code goes something like this:

CODE:...................

View 3 Replies View Related

Android :: Custom List Cursor Adaptor Crashes At BindView On Emulator - Not On Phone

Aug 23, 2010

I will try to be specific if I can - please be patient, first time asker and relatively new to programming on this platform. Apologies if this has been asked/answered before - please link it to me. I have searched up and down but find other unrelated (to me at least) problems.

The real puzzler for me is that my app is crashing on my emulator but when installed on my phone (via upload of apk to phone and then using an AppInstaller app from market) it works.

The crash comes from a NullPointerException at the numbered line in the following code snippet (my code) of a custom list cursor adapter.

CODE:....................

The following error dump is created.

CODE:..............

Curiously I have been happily programming and debugging away all day and out of the blue a long working and bug free portion of my app now throws up this error.

I suspect it might be a problem with the databases, but really not sure - nothing seems out of place there. Up until today I had a database with only one table - today I added a new table which also has a "_id" field as the name autoincrement key field, which I read in the docs was required for android list adapters (if memory serves). Having some experience in coding and some minor experience with databases, that seems like a bad idea to me but I am uncertain of if that is the problem and/or how else to do it.

The crash I am listing here does not display or make reference to the data in the other, new table. The cursor does not contain any query data from it. In fact if I rename the key field "_id" of the new table to something else (ie "_blah"), the crash remains.

Like I said, if I upload the apk to my phone, it works.

I have tried the following on the emulator:
- restarting adb (and eclipse) - no result
- uninstall from emulator - no result
- destory AVD profile and recreate - no result

I am developing this under the Android 2.1 SDK, and have been for the last few weeks. I have only ever had that SDK installed, I am yet to update to 2.2.

Not sure what else I can say here - hoping somebody here has experience enough to shed some light on it.

Without a fix to this, I can anticipate a very slow development process here on out (assuming I have to upload to my phone to test new code changes...).

View 3 Replies View Related

Android :: CursorAdapter Run In Background Thread?

Sep 24, 2010

Does the CursorAdapter run on a background thread and posts updates via the UI looper thread? If not what is the best pattern to load data asynchronously from a ContentProvider?

View 1 Replies View Related

Android : Notify CursorAdapter Changes In My Own ContentProvider

Dec 2, 2009

I am writing my own ContentProvider for my own application. And there is a ListView with a CursorAdapter pulling data from my Content Provider. My question is when there is a data change in my ContentProvider, how can I notify my CursorAdatper to requery the data and then have the ListView updated?

View 2 Replies View Related

Android :: Click In List View Item Changes Status Of Elements Inside Item?

Apr 9, 2010

I don't know exactly how to explain this problem, but I'll try. I have a ListView with several items. Each item has inside a TextView and two ImageView. I want the ImageView change when I click on them, and I want to open a context menu when I press for a long time into the ListView item.For the ImageView, everything works properly. For the whole item, I can show the context menu after a long press, but my problem is that the ImageView changes as well when I am pressing the TextView, for example.I hope you understand my problem. I think that all the children of a view are affected by an event in the parent, but I am not sure.

View 2 Replies View Related

Android :: OnClickListener In Listview Populated With A CursorAdapter

Nov 19, 2010

I have a list view with 2 buttons on each row. I am using a cursoradpater to populate the list. I am also using the view holder pattern on newview() bindview().

My questions are: where do i put the clicklisteners for the buttons knowing that the action for the button is different from the action of the list item itself? Do i keep the onListItemClick ?

View 1 Replies View Related

Android :: Apply Custom ListView For A CursorAdapter

Oct 31, 2009

I am building a custom listview used to list contacts from the contact cursor into a list with two text view for the phone number and name of the contact as well as a place for the images. I am getting a nullpoint error when i try to setText for my TextView Even though i checked the variable to see if they contained a string I have no ideas whats wrong with it. Code...

View 1 Replies View Related

Android :: Way To Deal With CursorAdapter - Switching Contacts API?

Nov 5, 2010

Does anyone tried to use CursorAdapter with old and new api?

Do you have some code examples of such solutions?

View 1 Replies View Related

Android :: Finalizing Cursor Error In Custom CursorAdapter

Sep 7, 2010

I have a cursor adapter and the logcat is filled with above errors, as soon as I click on a view. I am already releasing the CursorAdapter's cursor in onDestroy().Is there any way to get information about when the cursor was opened?

View 3 Replies View Related

Android :: Instant Refresh On CursorAdapter Attached To A ListView

Oct 14, 2009

I have a CursorAdapter attached to a ListView, the ListView contains checkboxes for every row. When I check/uncheck a checkbox in a row it will update it to a 0 or 1 in the database (This is working fine) I also have another checkbox in the same Activity that when pressed will disable all the checkboxes in the ListView [ setEnabled(false) ].

The problem is that when I press this checkbox the ListView checkboxes return to their initial state when I started the activity. It does not matter the number of checkboxes I changed during the activity.

However, if I press the back button and then re-enter the activity all modifications are saved because the Cursor is refreshed. I am calling notifyDataSetChanged() at the end of the the methods that disables all the checkboxes.

I also tried this for every checkbox in the ListView but it did not work (was unable to check a checkbox) Any ideas?

View 4 Replies View Related

Android :: How To Scroll Up When Choose Some Item At Item List?

Nov 20, 2010

I jave a list of item (linearlayout inside a scrollview where i add buttons vertically to linearlayout dynamically from the java code)i need when i click on one button the item moves up (scroll up) , to make the item at the first of the screen

View 1 Replies View Related

Android : Get An Item's Position From Item's ID In Droid Spinner?

May 25, 2010

I need to get an item's position in spinner knowing it's ID. I've tried to do it with Spinner and SpinnerAdapter classes but there are no corresponding methods there.

View 2 Replies View Related

Android :: How To Update CursorAdapter Tied To Listview When Number Of Items Changes?

Aug 16, 2010

I have a ListView backed by a custom adapter based on a CursorAdapter.The cursor I give it is based on a list of Notes in the database (each note is a DB row).Everything works just fine until I delete a note from the database. I'm not sure how to properly update the cursor/adapter/listview to display the new data.I've read conflicting posts on using adapter.notifyDataSetChanged() vs cursor.requery() to refresh the UI, but neither of them seems to work in this case.The only way I've been able to refresh it is by creating a new cursor from a new query and calling adapter.changeCursor(newCursor).Could someone demonstrate the proper way to update the backing data and then the UI (with psuedocode if possible).

View 2 Replies View Related

Android :: Run Query On Background Thread On Cursoradapter Doesn't Get Called?

Jul 25, 2010

I have a listactivity as a startup screen in my application. Which is displaying database records using custom cursor adapter. On create I set the filterable flag - getListView().setTextFilterEnabled(true)

My cursoradapter overrides runQueryOnBackgroundThread which runs corresponding query. The problem is that after typing some text and hitting enter, runQueryOnBackgroundThread never gets called. However, when the item click in the same view launches another activity(detail view of the record) and I come back to the original list activity, hitting back button, then text filtering works just fine. I don't call setTextFilterEnabled anywhere except during the initialization process and I can't really find any other API affecting this behavior, so any guesses why text filtering doesn't work initially, but all of the sudden starts working when I come back to the list activity from child activity?

View 3 Replies View Related

Android :: CursorAdapter Notify Data Set Changed Doesn't Work?

Jul 1, 2010

I'm trying to clean up some code and now I'm determined to get this seemless ListView updating working...

I want my ListView to be updated when I call notifyDataSetChanged() but nothing happens... I'm also passing the autoRequery flag to true when creating my CursorAdapter.

Cursor c = FavoritesHandler.getCategoryFavorites(getSQLiteInstance(), category); m_favoriteAdapter.changeCursor(c); startManagingCursor(c);

View 6 Replies View Related

Android :: Find Item In List Without Filtering List But Just Scrolling To That Item

Oct 17, 2010

Trying to implement simple dictionary. I want to make it so while the user is typing in the EditText box the list to scroll automatically to the best match. I don't want it to filter the list. For example if the user types "s" in the EditText I want the first word that s/he sees under the EditText box to be the first word in the dictionary that starts with "s." But the user should still be able to slide up and down and to be able to see the entire list of words. It is basically like a go to functionality. I used ArrayList to store my list of words. The data is in res/raw/data.xml file. Here is my onCreate method
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
wordListView = (ListView)findViewById(R.id.wordList);
myEditText = (EditText)findViewById(R.id.myEditText);
words = new ArrayList<Word>();
arrAdap = new ArrayAdapter<Word>(this, android.R.layout.simple_list_item_1, words);
wordListView.setAdapter(arrAdap); try {
InputStream inSource = getResources().openRawResource(R.raw.data);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(inSource, null);
NodeList wordsList = doc.getElementsByTagName("eng-bg");
int length = wordsList.getLength();
for(int i = 0; i<length; i++) {
Element entry = (Element)wordsList.item(i);
Element eng = (Element)entry.getElementsByTagName("english").item(0);
Element bul = (Element)entry.getElementsByTagName("bulgarian").item(0);
Element id = (Element)entry.getElementsByTagName("ID").item(0);
String english = eng.getFirstChild().getNodeValue();
String bulgarian = bul.getFirstChild().getNodeValue();
int wordId = Integer.parseInt(id.getFirstChild().getNodeValue());
Word word = new Word(bulgarian, english, wordId);
addNewWord(word);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}wordListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
selectedWord = words.get(pos);
showDialog(TRANS_DIALOG);
myEditText.setText(selectedWord.getEnglish());
myEditText.addTextChangedListener(new TextWatcher(){
public void onTextChanged(CharSequence s, int start, int before, int count) {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub

View 1 Replies View Related

Android :: Open Helper To Open Database And Get A Cursor To Pass To CursorAdapter

Jul 1, 2010

I have a ListActivity that uses a CursorAdapter to fill the rows in the view. I wrote a database helper class that gives me back results for common queries I make for my app, and it uses an SQLiteOpenHelper implementation I wrote to open the database. I use the open helper to open the database and get a cursor to pass to my CursorAdapter.

Here's a code snippet:

CODE:...................

The problem I'm having, that I didn't have before I implemented the open helper (before I just opened the database directly without a helper), is when I click on an item, which takes me to another activity, and then go back to this activity. When it initializes everything is fine, and my list is populated fine, but when I go back from the activity that follows, the list is empty and in the LogCat I see "Invalid statement in fillWindow()".

It appears from a few post I've seen that the reason is, when I requery the cursor, the database is closed. But I'm not closing it! I'm scratching my head on this one.

View 2 Replies View Related

Android :: Menu Item Separetor (menu Item In Different Line)

Jun 2, 2010

How can i define each menu item in different line? Right now if I'm adding 4 items they will get the form of 2X2. Is there a way to add them differently? Like 1 item and 3 below it? or 1X4?

View 1 Replies View Related

Android :: Calling Web Service

Sep 6, 2010

I am currently working on an application in android where I need to call the Web Service. I am working in Android and I don't have an idea about how to call a web Service in Android.So, can anybody please help me out in how to call a Web Service in Android Programming.

View 1 Replies View Related

Android :: Calling .net Webservice From App

Jan 11, 2010

Best way of calling an asp.net web service from my android app. I am planning on using ksoap2 ? Is this a good route to go, or is that the only way to go? Do I have other options? What is the most efficient way if there are other options?

View 5 Replies View Related

Android :: OnLocationChanged Not Calling / Way To Fix?

Apr 30, 2010

I write a class which implements LocationListener. Its just listening to the location. I tried the code in Tatoo, but its not working. The code is...

View 4 Replies View Related

Android :: App For Video Calling

Apr 2, 2009

I want to develop an application containing video call, but I didn't find the interface in Android about video call. So I wonder whether Android has this API in fact, if anyone know it, please tell me.

View 2 Replies View Related

Android :: Calling StartActivity From Outside Of An Activity

Dec 7, 2009

I have a TabActivity subclass that attempts to start a new activity via a menu item selection in onOptionsItemSelected.I am receiving the following exception which eludes me at the moment.I'm not sure why it thinks I am *not* in an activity!

View 2 Replies View Related

Android :: Calling GeoCoder GetFromLocation

Mar 23, 2010

I'm having a problem calling GeoCoder.getFromLocation();

I have a LocationListener calling an updateLocation() method in my class, which in turns calls GeoCoder.getFromLocation() with the current location.

CODE:............

When I run this code on a device (HTC Magic 1.6) I get the following error :

D/LocationMasfClient(15392): getAddressFromProtoBuf(): Ignore feature 0,1er Arrondissement Paris D/AndroidRuntime(21403): Shutting down VM W/dalvikvm(21403): threadid=3: thread exiting with uncaught exception (group=0x4001da38) E/AndroidRuntime(21403): Uncaught handler: thread main exiting due to uncaught exception

If I run the same code on an emulator (1.6 with google api) the error I get is :

D/GpsLocationProvider(52): setMinTime 0 E/LocationMasfClient(52): reverseGeocode(): no feature in GLocation

View 2 Replies View Related

Android :: Errors On Calling Web Services

Aug 8, 2009

When i am calling the web services i got his errors. i added the internet permissions in android manifest.xml file 08-08 15:40:09.127: INFO/aSizzle(198): statusCode>>>500 08-08 15:40:09.158: INFO/aSizzle(198): statusLine>>>HTTP/1.1 500 Internal Server Error

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved