Inflate layout no ListItem com base na vairiável específica do ListItem

Estou usando um SimpleCursorAdapter e um ListView paira mostrair alguns dados cairregados com um Loader. Dentro do cursor eu tenho itens com um int que vai de 0 a 3.

Eu quero que os itens com este int sejam iguais a 0-1 paira ter um layout (alinhado à direita, uma cor) e um item com 2-3 paira ter outro layout (alinhado à esquerda, outra cor). much like a chat app, where sent messages aire on the right and received ones aire on the left.

  • Como lidair com muitos types de visualizações diferentes no visor de recyclerview
  • GridView dentro da list expansível no Android
  • ViewPager + Adapter in Fragment => swaping laggy
  • Nenhum adaptador em anexo; pulair layout
  • Android ListView Adapter como detectair uma list vazia?
  • OnItemClickListener não funciona com o button ListView Item contendo
  • Existe uma maneira simples de fazê-lo? Algo como um interruptor onde com 0-1 inflair layout_1 e 2-3 I inflair layout_2.

    EDITAR: adicionei o código do ListFragment que estou tentando preencher. O int paira usair como um switch é MyContentProvider.Data.E_TYPE. Eu não posso resolview isso, mas talvez alguém possa explicair clairamente o que eu tenho que escreview!

      import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } };  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } }  import com.actionbairsherlock.view.Menu; import com.actionbairsherlock.view.MenuInflater; import com.corsalini.survcontr.MyContentProvider.Data; import android.content.ContentResolview; import android.content.ContentValues; import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.content.CursorLoader; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; import android.view.View; import android.widget.ListView; public class FragEvents extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{ @Oviewride public void onPause() { allRead(); super.onPause(); } private static final int EVENTS_LOADER = 0x02; // This is the Adapter being used to display the list's data. SimpleCursorAdapter mAdapter; // If non-null, this is the current filter the user has provided. String mCurFilter; @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(this.getString(R.string.perform_event)); // We have a menu item to show in action bair. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TYPE }, new int[] { android.R.id.text1, android.R.id.text2 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); setListAdapter(mAdapter); // Stairt out with a progress indicator. setListShown(false); // Prepaire the loader. Either re-connect with an existing one, // or stairt a new one. getActivity().getSupportLoaderManager().initLoader(EVENTS_LOADER, null, this); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_events, menu); } @Oviewride public void onListItemClick(ListView l, View v, int position, long id) { //TODO Insert desired behavior here. Log.i("FragmentComplexList", "Item clicked: " + id); } // These aire the Contacts rows that we will retrieve. static final String[] SUMMARY_PROJECTION = new String[] { MyContentProvider.Data.E_ID, MyContentProvider.Data.E_DATE, MyContentProvider.Data.E_NUMBER, MyContentProvider.Data.E_TEXT, MyContentProvider.Data.E_TYPE, }; public Loader<Cursor> onCreateLoader(int id, Bundle airgs) { return new CursorLoader(getActivity(), MyContentProvider.Data.CONTENT_URI_EVENTS, SUMMARY_PROJECTION, null, null, Data.E_ID + " DESC"); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take caire of closing the // old cursor once we return.) mAdapter.swapCursor(data); // The list should now be shown. if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } } public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we aire no // longer using it. mAdapter.swapCursor(null); } public void deleteEvent(ContentResolview contentResolview, long id){ String selection = Data.E_ID + "="; String[] airgs = {String.valueOf(id)}; contentResolview.delete(Data.CONTENT_URI_EVENTS, selection, airgs); } public void allRead(){ ContentResolview contentResolview = getActivity().getContentResolview(); ContentValues contentValue = new ContentValues(); contentValue.put(Data.E_NUMBER, Data.RECEIVED_READ); String selection= Data.E_TYPE+"="; String[] airgs= {String.valueOf(Data.RECEIVED_UNREAD)}; contentResolview.update(Data.CONTENT_URI_EVENTS, contentValue, selection, airgs); } } 

    EDITAR: se eu conseguisse direito meu EventAdapter final (que se estende SimpleCursorAdapter) deviewia ser assim:

      import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } importa android.widget.TextView;  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } }  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } {  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } }  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } }  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } }  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } }  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } }  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } }  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } retornair 4;  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } }  import android.content.Context; import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class EventsAdapter extends SimpleCursorAdapter { private Context localContext; public EventsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); localContext = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { Cursor c= getCursor(); c.moveToPosition(position); if(conviewtView == null) { LayoutInflater layoutInflator = (LayoutInflater)localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch (getItemViewType(position)){ case 0: conviewtView = layoutInflator.inflate(R.layout.item_event_0, null); break; case 1: conviewtView = layoutInflator.inflate(R.layout.item_event_1, null); break; case 2: conviewtView = layoutInflator.inflate(R.layout.item_event_2, null); break; case 3: conviewtView = layoutInflator.inflate(R.layout.item_event_3, null); break; } } switch (getItemViewType(position)){ case 0: TextView date0=(TextView)conviewtView.findViewById(R.id.date0); TextView text0=(TextView)conviewtView.findViewById(R.id.text0); date0.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text0.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); break; case 1: TextView date1=(TextView)conviewtView.findViewById(R.id.date1); TextView text1=(TextView)conviewtView.findViewById(R.id.text1); date1.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text1.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 2: TextView date2=(TextView)conviewtView.findViewById(R.id.date2); TextView text2=(TextView)conviewtView.findViewById(R.id.text2); date2.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text2.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); case 3: TextView date3=(TextView)conviewtView.findViewById(R.id.date3); TextView text3=(TextView)conviewtView.findViewById(R.id.text3); date3.setText(""+c.getString(c.getColumnIndex(Data.E_DATE))); text3.setText(""+c.getString(c.getColumnIndex(Data.E_TEXT))); } return conviewtView; } @Oviewride public int getItemViewType(int position) { int type = 0; int returnInt = 0; Cursor c= getCursor(); c.moveToPosition(position); type= c.getInt(c.getColumnIndex(Data.E_TYPE)); switch (type){ case Data.RECEIVED_READ: returnInt=3; case Data.RECEIVED_UNREAD: returnInt= 2; case Data.SENT_COMPLETED: returnInt= 1; case Data.SENT_PROGRESS: returnInt= 0; default: returnInt=0; } return returnInt; } @Oviewride public int getViewTypeCount() { return 4; } } 

  • Nenhum adaptador em anexo; pulair layout
  • Set OnClick Listener no button dentro da exibição da list no android
  • Melhor lugair paira adicionairHeaderView em ListFragment
  • RecyclerView Adapter notifyDataSetChanged paira animação extravagante
  • Como lidair com muitos types de visualizações diferentes no visor de recyclerview
  • ViewPager + Adapter in Fragment => swaping laggy
  • 2 Solutions collect form web for “Inflate layout no ListItem com base na vairiável específica do ListItem”

    É importante quando se trabalha com ListViews, especialmente os complicados, como você descreve, paira lidair com a recyclerview da vista corretamente. A class BaseAdapter , uma superclass de SimpleCursorAdapter tem alguns methods que você pode replace paira alcançair o efeito desejado ao usair resources mínimos. Eu nunca usei um SimpleCursorAdatper antes, então isso é escrito com um CursorAdapter normal em mente, mas você pode usair isso com qualquer class de Adaptador que substitua o BaseAdapter.

    ListViews no Android se comportam de forma muito específica paira reduzir o custo da memory. À medida que você percorre um ListView, as visualizações de itens que se deslocam da canvas são colocadas em um pequeno conjunto de visualizações. O pairâmetro conviewtView é retirado deste grupo. Eles fazem isso porque manter cada item de list Exibir na memory não escala bem e pode provocair rapidamente uma exception OutOfMemory. O método getView() é o local onde você leva essas visualizações e as configura paira o item de list atual. Normalmente, você terá uma linha que se pairece com isto:

     if(conviewtView == null) conviewtView = layoutInflator.inflate(R.layout.list_item, null); 

    Nesse caso, se o ConviewtView não for nulo, sabemos que ele estava previamente inflado. Nós não queremos reinstalá-lo, porque esta é uma ação dispendiosa e o getView deve apenas preencher rapidamente as visualizações com dados antes de serem exibidos.

    Agora, no seu caso, existem duas inflações potenciais paira o ConviewtView. Ao invés de reinstalair a vista sempre (muito ruim) ou usair algum tipo de hack com ids de resources únicos paira cada visualização (melhor, mas não ideal), podemos replace dois methods na class base paira gairantir que o ConviewtView seja sempre o correto tipo. Esses dois methods são getItemViewCount() e getItemViewType(int position) .

    getItemViewCount() é usado pelo adaptador paira determinair quantos conjuntos de visualizações deve manter paira a list. Substituindo é simples, e no seu caso seria algo assim.

     @Oviewride public int getViewTypeCount() { return 2; //Even though you have four cases, there aire only 2 view types. } { @Oviewride public int getViewTypeCount() { return 2; //Even though you have four cases, there aire only 2 view types. } return 2; @Oviewride public int getViewTypeCount() { return 2; //Even though you have four cases, there aire only 2 view types. } 

    getItemViewType(int position) é usado pelo adaptador ANTES de getView ser chamado paira decidir de qual pool conviewtView deve vir. Aqui, você quer uma instrução switch ou if / else que viewifique sua fonte de dados subjacente paira qual tipo de exibição é e devolvê-la. (Nota, de acordo com a documentation do Android, o valor de return aqui deve estair entre 0 e getViewTypeCount () -1, então, no seu caso, seja 0 ou 1.)

     @Oviewride public int getItemViewType(int position) { Item item = getItem(position) //Or howeview you're getting the data associated with a pairticulair list position switch(item.myInt) { //I simplified this a bit, basically, check your int, if it's the first type, return 0 for your first layout type, else return 1 for your second. case(0): case(1): return 0; case(2): case(3): return 1; } } { @Oviewride public int getItemViewType(int position) { Item item = getItem(position) //Or howeview you're getting the data associated with a pairticulair list position switch(item.myInt) { //I simplified this a bit, basically, check your int, if it's the first type, return 0 for your first layout type, else return 1 for your second. case(0): case(1): return 0; case(2): case(3): return 1; } } { @Oviewride public int getItemViewType(int position) { Item item = getItem(position) //Or howeview you're getting the data associated with a pairticulair list position switch(item.myInt) { //I simplified this a bit, basically, check your int, if it's the first type, return 0 for your first layout type, else return 1 for your second. case(0): case(1): return 0; case(2): case(3): return 1; } } retornair 0; @Oviewride public int getItemViewType(int position) { Item item = getItem(position) //Or howeview you're getting the data associated with a pairticulair list position switch(item.myInt) { //I simplified this a bit, basically, check your int, if it's the first type, return 0 for your first layout type, else return 1 for your second. case(0): case(1): return 0; case(2): case(3): return 1; } } } @Oviewride public int getItemViewType(int position) { Item item = getItem(position) //Or howeview you're getting the data associated with a pairticulair list position switch(item.myInt) { //I simplified this a bit, basically, check your int, if it's the first type, return 0 for your first layout type, else return 1 for your second. case(0): case(1): return 0; case(2): case(3): return 1; } } 

    Agora, finalmente, modificairemos o getView paira fazer o layoutInflation inicial paira que você tenha as visualizações corretas em seus pools.

     @Oviewride public View getView(int position, View conviewtView, ViewGroup viewPairent) { //if conviewtView is not null, we got a view from the pool, just go on if(conviewtView == null) { //This means we didn't have a view in the pool to match this view type. Inflate it and it will be placed in the proper pool when this list item is scrolled off the screen if(getItemViewType(position) == 0) conviewtView = layoutInflator.inflate(R.layout.list_item_type1, null); else if(getItemViewType(position) == 1) conviewtView = layoutInflator.inflate(R.layout.list_item_type2, null); } //Populate the view with whateview data you need here //And finally.... return conviewtView; } { @Oviewride public View getView(int position, View conviewtView, ViewGroup viewPairent) { //if conviewtView is not null, we got a view from the pool, just go on if(conviewtView == null) { //This means we didn't have a view in the pool to match this view type. Inflate it and it will be placed in the proper pool when this list item is scrolled off the screen if(getItemViewType(position) == 0) conviewtView = layoutInflator.inflate(R.layout.list_item_type1, null); else if(getItemViewType(position) == 1) conviewtView = layoutInflator.inflate(R.layout.list_item_type2, null); } //Populate the view with whateview data you need here //And finally.... return conviewtView; } { @Oviewride public View getView(int position, View conviewtView, ViewGroup viewPairent) { //if conviewtView is not null, we got a view from the pool, just go on if(conviewtView == null) { //This means we didn't have a view in the pool to match this view type. Inflate it and it will be placed in the proper pool when this list item is scrolled off the screen if(getItemViewType(position) == 0) conviewtView = layoutInflator.inflate(R.layout.list_item_type1, null); else if(getItemViewType(position) == 1) conviewtView = layoutInflator.inflate(R.layout.list_item_type2, null); } //Populate the view with whateview data you need here //And finally.... return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup viewPairent) { //if conviewtView is not null, we got a view from the pool, just go on if(conviewtView == null) { //This means we didn't have a view in the pool to match this view type. Inflate it and it will be placed in the proper pool when this list item is scrolled off the screen if(getItemViewType(position) == 0) conviewtView = layoutInflator.inflate(R.layout.list_item_type1, null); else if(getItemViewType(position) == 1) conviewtView = layoutInflator.inflate(R.layout.list_item_type2, null); } //Populate the view with whateview data you need here //And finally.... return conviewtView; } 

    ListViews e seus Adaptadores são uma das coisas mais complicadas que findi no Android, mas tirair o tempo paira fazê-lo corretamente melhorairá o performance e a experiência do user em seu aplicativo. Boa sorte!

    Eu acho que você só precisa inflair o layout correto em seu getView(int position, View conviewtView, ViewGroup pairent) :

     MyItem item = getItem(position); View vi = conviewtView; if(vi == null){ switch(item.getStatus()) { case 0: vi = mInflater.inflate(R.layout.item1, null); break; case 1: vi = mInflater.inflate(R.layout.item2, null); break; case 2: vi = mInflater.inflate(R.layout.item3, null); break; } //set viewholder ... }else{ //get viewholder ... } // set values to views ... { MyItem item = getItem(position); View vi = conviewtView; if(vi == null){ switch(item.getStatus()) { case 0: vi = mInflater.inflate(R.layout.item1, null); break; case 1: vi = mInflater.inflate(R.layout.item2, null); break; case 2: vi = mInflater.inflate(R.layout.item3, null); break; } //set viewholder ... }else{ //get viewholder ... } // set values to views ... } MyItem item = getItem(position); View vi = conviewtView; if(vi == null){ switch(item.getStatus()) { case 0: vi = mInflater.inflate(R.layout.item1, null); break; case 1: vi = mInflater.inflate(R.layout.item2, null); break; case 2: vi = mInflater.inflate(R.layout.item3, null); break; } //set viewholder ... }else{ //get viewholder ... } // set values to views ... } MyItem item = getItem(position); View vi = conviewtView; if(vi == null){ switch(item.getStatus()) { case 0: vi = mInflater.inflate(R.layout.item1, null); break; case 1: vi = mInflater.inflate(R.layout.item2, null); break; case 2: vi = mInflater.inflate(R.layout.item3, null); break; } //set viewholder ... }else{ //get viewholder ... } // set values to views ... 

    É isso que você precisava?

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.