android - Editing list view items dynamically when using cursor adapters and loaders -
I am writing a small messaging app and I have had this problem recently.
I have a My question is, how do you change a line background in this case? Do I have to access it through the adapter? I'm pretty sure that this should be done in the } This should help! ListFragment subclass, which implements the
cursor loader callback. The built-in
ListView is linked to a
SimpleCursorAdapter . Each line view in this list has a layer illustration in the form of a background, I want to switch between the levels based on the database information (whether the message was sent or not).
onLoadFinished method. But this code gives me the
NullPointerException you can talk me in the right direction, I would be really grateful < / P>
Public Class MessagesFragment ListFragment LoaderManager.LoaderCallbacks Extends the apply. Cursor & gt; {Private Static MessagesFragment piece; Private stable main activity activity; Private Static SimpleCursor Adapter Adapter; Public static messagesFragment getInstance () {if (fragment == null) fragment = new messagesFragment (); Return piece; } @ Override Crate on Public Zero (Bundle Saved Instantstate) {Super.Nought (Saved Instantstate); Activity = (main activity) getActivity (); Adapter = New SimpleCursorAdapter (Activity R.layout.list_item, Null, New String [] {DataProvider.KEY_NUMBER, DataProvider.KEY_MESSAGE, DataProvider.KEY_TIME}, New Integer [] {R.id.item_field_number, R.id.item_field_message, R .id.item_field_time}, 0); SetListAdapter (adapter); GetLoaderManager (). InitLoader (0, empty, this); } @Override Public View onCreateView (LayoutInflater inflater, ViewGroup container, bundled savedInstanceState) {return inflater.inflate (R.layout.fragment_messages, faucet); } @ Override Public Wide OnListEightClick (ListView L, View V, Int Position, Long ID) {Super. Analystimeclic (L, V, Position, ID); Activity.showDetails (Long.valueOf (ID) .intValue ()); } @ Override Public Loader & lt; Cursor & gt; OnCreateLoader (integer ID, bundle args) {New CursorLoader (Activity DataProvider.CONTENT_URI, Null, Null, Null, Faucet) Return; } @ Override Public Wide Onload Load (Loader & lt; Cursor> Loader, Cursor Data) {adapter.swapCursor (Data); Whereas (data.moveToNext ()) {int id = data.getInt (data.getColumnIndex (DataProvider.KEY_ID)); Int sent = data. GetInt (data.getColumnIndex (DataProvider.KEY_SENT)); . This.getListView () getChildAt (ID) .getBackground () setLevel (sent). }} @ Override Public Wide Onloader Reset (Loader & lt; Cursor> Loader) {adapter.swapCursor (null); }
Comments
Post a Comment