0

我的目标是水平滑动列表,这些列表由公共类 ClientsManagerOpenHandler 扩展 SQLiteOpenHelper 填充。我尝试通过使用 viewpager 和 ListFragments 来实现这个目标。如果您有其他解决方案,请告诉我。

现在的问题:如果我尝试从以下 PageListFragment.java 调用,来自 ClientsManagerOpenHandler 的数据程序崩溃:

 dbCursorTerminAnsicht = openHandler.queryTabelle("terminansicht"); 

也许我不能在 ListFragment 中调用扩展的 SQLiteOpenHelper?但是我如何将 sqlite 中的数据获取到我的列表中,以及当我水平滑动以更改数据时......

请帮忙。我已经尝试过任何事情,但我现在真的需要帮助。

public class PageListFragment extends ListFragment implements OnClickListener,
    LoaderCallbacks<Cursor> {

private Calendar cal = Calendar.getInstance();
private ClientsManagerOpenHandler openHandler;
public static final String PREFS_NAME ="MyPrefsFile";
SharedPreferences prefs;`

private Cursor dbCursorTerminAnsicht;
private Integer intVerdienst = 0;
private String queryVerdienst;
private SimpleCursorAdapter mCursorAdapter;
private ListView listViewTermine;
private final int listNr;
private final String[] fruit = { "Bananen", "Apfle", "Erdbeere",
        "Kirschen", "Mangos" };
private Uri[] mMediaSource = {null, MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI};

public PageListFragment(int nr) {
    this.listNr = nr;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


//!!!!! after the next line the program crashes. Even I have set breakpoints at ClientsManagerOpenHandler 
//I cannot see anything in the debugger (Debugger: Source not found...) 


    dbCursorTerminAnsicht = openHandler.queryTabelle("terminansicht"); 

    if (listNr == 0) {
        ArrayAdapter<String> openHandler = new ArrayAdapter<String>(
                getActivity(), android.R.layout.simple_list_item_1, fruit);
        setListAdapter(openHandler);
    } else if (listNr == 1) {
        mCursorAdapter = new SimpleCursorAdapter(getActivity(),
                android.R.layout.simple_list_item_1, null,
                new String[] { MediaStore.Audio.Artists.ARTIST },
                new int[] { android.R.id.text1 }, 0);
        setListAdapter(mCursorAdapter);
        getLoaderManager().initLoader(0, null, this);
    } else if (listNr == 2) {

        openHandler = new ClientsManagerOpenHandler(getActivity());
         String query = "projekte, klienten, termine WHERE termine.KLIENTID = klienten._id AND termine.PROJEKTID = projekte._id ORDER BY BEGINN ASC;";



        MyDataAdapter myClientsadapter = new MyDataAdapter (
                getActivity(),
                  R.layout.terminzeile,
                 // android.R.layout.two_line_list_item,
                  dbCursorTerminAnsicht,
                 new String[] { openHandler.BEGINN , openHandler.ENDE, openHandler.NACHNAME, openHandler.VORNAME, openHandler.PROJEKT, openHandler.BEZAHLT},
                 // fields,
                //  new int[] {R.id.editTextNachname, R.id.editTextVorname }
                  new int[] {R.id.textViewBeginn, R.id.textViewEnde, R.id.textViewNachname, R.id.textViewVorname, R.id.textViewProjekt,R.id.checkBoxBezahlt }
                  );


        myClientsadapter.setViewBinder(new MyDataAdapter.ViewBinder() {
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {


                if(columnIndex == 13) {
                        String strBeginn = cursor.getString(columnIndex);
                        CheckBox cb = (CheckBox) view;
                        int intbezahlt = cursor.getInt(13);
                        int index = cursor.getColumnIndex("SATZ");
                        Integer intSatz = cursor.getInt(index);
                        if (index>0) {
                            if (intbezahlt>0){
                                intVerdienst = intVerdienst + intSatz;
                            }
                        }
                        cb.setChecked(intbezahlt > 0);
                        return true;
                }

                String str = cursor.getString(columnIndex);
                return false;
            }
        });

        //TerminlisteRefresh("");

        setListAdapter(myClientsadapter);
        getLoaderManager().initLoader(0, null, this);
    }
}


public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
    Loader<Cursor> loader = new CursorLoader(getActivity(), mMediaSource[listNr],
            null, null, null, null);
    return loader;
}


public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
    mCursorAdapter.swapCursor(cursor);

}


public void onLoaderReset(Loader<Cursor> arg0) {
    mCursorAdapter.swapCursor(null);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}





}
4

1 回答 1

0

您似乎在定义之前尝试访问openHandler它:

dbCursorTerminAnsicht = openHandler.queryTabelle("terminansicht");
...
openHandler = new ClientsManagerOpenHandler(getActivity());

这可能会更好:

openHandler = new ClientsManagerOpenHandler(getActivity());
dbCursorTerminAnsicht = openHandler.queryTabelle("terminansicht");
于 2012-05-03T18:51:44.223 回答