ListFragment Custom CursorAdapter und FragmentPagerAdapter

  • 1 Antworten
  • Letztes Antwortdatum
L

loocker

Neues Mitglied
3
Hi,
ich habe eine SherlockFragmentActivity welche einen FragmentPagerAdapter enthält welche das SherlockListFragment aufruft. Das Problem ist jetzt, dass das ListFragment kein Daten anzeigt mittels CustomCursorAdapter. Die Methode bindView() und newView() im CustomCursorAdapter wird nie aufgerufen, laut Log. Die Frage ist warum ich keine Daten angezeigt bekomme.

Code:
public class SektionListFragment extends SherlockListFragment implements LoaderManager.LoaderCallbacks<Cursor>
{
 
 /** Kuerzel fuers Logging. */
 private static final String TAG = SektionListFragment.class.getSimpleName();
 
 private RouteCustomCursorAdapter mAdapter;  
 private LoaderManager mLoaderManager;  
 private Loader mLoader;  
 private Cursor mCursor;
 private RouteSpeicher mRouteSpeicher;
 private String mRouteSektion;
 private boolean schonBesucht;
 private SharedPreferences einstellungen;
 public static final String IN_PARAM_ROUTE_SEKTION = "ROUTE_SEKTION";
 
 public SektionListFragment() {
  super();
 }   
 
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
 
  Bundle extras = getArguments();
  mRouteSektion = extras.getString(IN_PARAM_ROUTE_SEKTION);
 
  mRouteSpeicher = new RouteSpeicher(getActivity());
  mLoader = getLoaderManager().initLoader(0, null, this);  
  mAdapter = new RouteCustomCursorAdapter(getActivity(), mCursor);
 
 }
   @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.custom_list, container, false);
     }
   @Override
   public void onActivityCreated(Bundle savedInstanceState)
   {
    super.onActivityCreated(savedInstanceState);
    this.getListView().
    setAdapter(mAdapter);
 }
 
   @Override
      public void onListItemClick(ListView l, View v, int position, long id) {
          Log.i("FragmentList", "Item clicked: " + id);
      }
   public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1)
   {
    return new CursorLoader(getActivity())
    {
     public Cursor loadInBackground()
     {
 
      einstellungen = Einstellungen.getAnwendungsEinstellungen(getActivity());
      schonBesucht = einstellungen.getBoolean("schon_besucht", false);
 
      mRouteSpeicher.oeffnen();
      mCursor = mRouteSpeicher.ladeRouteListe(mRouteSektion, schonBesucht);
      }
mRouteSpeicher.schliessen();
      return mCursor;
     }
    };
   } 
 
 @Override
 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    mRouteSpeicher.oeffnen();
  if (mCursor != null) {
   mCursor = mRouteSpeicher.ladeRouteListe(mRouteSektion, schonBesucht);
   mAdapter.swapCursor(mCursor);
   }
  else
   mAdapter.swapCursor(mCursor);
  mRouteSpeicher.schliessen();
  //mAdapter.swapCursor(cursor);
 
 }
 @Override
 public void onLoaderReset(Loader<Cursor> loader) {
  mAdapter.swapCursor(null);  
 }
}

Code:
[SIZE=2][COLOR=#7f0055]

[B][SIZE=2][COLOR=#7f0055]public
[/COLOR][/SIZE][/B][/COLOR][/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] RouteCustomCursorAdapter [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] CursorAdapter {[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] LayoutInflater [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mInflater[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Context [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mContext[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Cursor [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mCursor[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] RouteCustomCursorAdapter(Context context, Cursor c) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](context, c, 0);[/SIZE][/LEFT]
 
[LEFT][SIZE=2]}[/SIZE][/LEFT]
[SIZE=2][COLOR=#3f7f5f]
[LEFT][/COLOR][/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mContext[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = context;[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mCursor[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = c;[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] View newView(Context context, Cursor cursor, ViewGroup parent)[/SIZE]
[SIZE=2]{Log.[I]i[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"test"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"hallo"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mInflater[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = LayoutInflater.[I]from[/I](parent.getContext()); [/SIZE]
[SIZE=2]View retView = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mInflater[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].inflate(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]custom_list_zeile[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], parent, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]false[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ViewHolder holder = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ViewHolder();[/SIZE]
[SIZE=2]holder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtNummer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (CheckedTextView) retView.findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]checkedText_route_nummer[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]holder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (TextView) retView.findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]tx_route_name[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]holder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtBewertung[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (TextView) retView.findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]tx_route_bewertung[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2]retView.setTag(holder);[/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] retView;[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] bindView(View view, Context context, Cursor cursor) [/SIZE]
[SIZE=2]{[/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ViewHolder holder = (ViewHolder) view.getTag();[/SIZE][/LEFT]
 
[LEFT][SIZE=2]holder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtNummer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setText(cursor.getString(cursor.getColumnIndex(RouteTbl.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]NUMMER[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])));[/SIZE]
[SIZE=2]holder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtNummer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setChecked(cursor.getInt(cursor.getColumnIndex(RouteTbl.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SCHON_BESUCHT[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]))==0? [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]false[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]:[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE]
[SIZE=2]holder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setText(cursor.getString(cursor.getColumnIndex(RouteTbl.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]NAME[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])));[/SIZE]
[SIZE=2]holder. [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtBewertung[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setText(cursor.getString(cursor.getColumnIndex(RouteTbl.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]NAME[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])));[/SIZE][/LEFT]
 
 
[LEFT][SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ViewHolder {[/SIZE]
[SIZE=2]CheckedTextView [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtNummer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]TextView [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]TextView [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]txtBewertung[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] View getView([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] position, View v, ViewGroup parent){[/SIZE]
[SIZE=2]Log.[I]i[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"test"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"hallo3"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]View mView = v;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (mView == [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]){[/SIZE]
[SIZE=2]LayoutInflater vi = (LayoutInflater)[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mContext[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getSystemService(Context.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LAYOUT_INFLATER_SERVICE[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]mView = vi.inflate(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]custom_list_zeile[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], parent, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]false[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);;[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][SIZE=2]TextView text = (TextView)mView.findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]tx_route_bewertung[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]text.setTextColor(Color.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]WHITE[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]text.setText([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mCursor[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getString([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mCursor[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getColumnIndex(RouteTbl.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]NAME[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])));[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] mView;[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]
 
So ich konnte das Problem eingrenzen, wenn ich ein SimpleCursorAdapter verwende und das Android simple_list_item_1 Layout verwende werden Daten angezeigt, so bald ich aber mein eigenes Layout in der OnCreateView Methode lade, bleibt die Liste leer, warum? Lade ich das Layout falsch, in einer ListActivity lade ich das Layout normalerweise mit setContentView(), aber das funktioniert in einem ListFragment ja nicht. Jemand eine Idee?
 
Zurück
Oben Unten