0

每次在 ListView 上单击一个项目时,我都会尝试启动一项活动,我在我的项目中使用数据库并在我的项目中使用全局变量,但无法在项目中启动 GalleryFileActivity 活动如果您需要了解每个部分也将提供感谢您不断努力推进完美

公共类 DataListView 扩展 ListActivity {

final private ArrayList<String> results = new ArrayList<String>();
private String tableName = DBHelper.tableName;
private SQLiteDatabase newDB;
private String Path;
final private ArrayList<String> pikh = new ArrayList<String>();

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

    final global folder = ((global)getApplicationContext());
    openAndQueryDatabase();

    displayResultList();


}
private void displayResultList() {
    TextView tView = new TextView(this);
    tView.setText("data is");
    getListView().addHeaderView(tView);


    setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, results));

    ListView lstView = getListView();


   lstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);        
   lstView.setTextFilterEnabled(true);

}
    public void onListItemClick(
            ListView parent, View v, int position,long id, global folder)
            {
        String pos=results.get(position-1);
        super.onListItemClick(parent, v, position, id);
                Toast.makeText(this,
                    "You have selected "  + results.get(position-1) ,
                    Toast.LENGTH_SHORT).show();
                folder.setsubfolder (pos);
            **startActivity(new Intent(this,GalleryFileActivity.class));**
            }

            public void onClick(View view) {
                ListView lstView = getListView();

            }

private void openAndQueryDatabase() {
    try {
        DBHelper dbHelper = new DBHelper(this.getApplicationContext());
        newDB = dbHelper.getWritableDatabase();
        Cursor c = newDB.rawQuery("SELECT Path, Header FROM resource1  " 
                 , null);

        if (c != null ) {
            if  (c.moveToFirst()) {
                do {

                    Path = c.getString(c.getColumnIndex("Path"));
                    String Header = c.getString(c.getColumnIndex("Header"));

                    results.add( Path + "    " + Header);


                }while (c.moveToNext()) ;

            } 
        }           
    } catch (SQLiteException se ) {
        Log.e(getClass().getSimpleName(), "Could not create or Open the database");
    } finally {
        if (newDB != null) 
            newDB.execSQL("DELETE FROM " + tableName);
            newDB.close();
    }

}

}

4

1 回答 1

1

代码看起来差不多。

听起来您可能没有GalleryFileActivity在清单中声明。

检查您的 logcat 输出 - 那里可能有一个例外提到这一点。

于 2013-04-18T21:57:05.447 回答