ActionBarActivity“android-support-v7-appcompat”与listactivity和CursorAddWater在同一活动中的活动

ActionBarActivity“android-support-v7-appcompat”与listactivity和CursorAddWater在同一活动中的活动,android,android-actionbar-compat,Android,Android Actionbar Compat,我正在尝试扩展actionbaractivity而不是listactivity现在的问题是actionbar活动需要我来实现导航抽屉,listactivity需要列表显示为java dosent支持多重继承我无法使用它。如何在同一个活动中实现列表和actionbar在下面的代码中 public class dbMainactivty extends ListActivity { // Declare Variables public static final String RO

我正在尝试扩展actionbaractivity而不是listactivity现在的问题是actionbar活动需要我来实现导航抽屉,listactivity需要列表显示为java dosent支持多重继承我无法使用它。如何在同一个活动中实现列表和actionbar在下面的代码中

public class dbMainactivty extends ListActivity {

    // Declare Variables
    public static final String ROW_ID = "row_id";
    private static final String TITLE = "title";
    private ListView noteListView;
    private CursorAdapter noteAdapter;

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

        // Locate ListView
        noteListView = getListView();
    //  setContentView(R.layout.list_note);
        //noteListView = (ListView) findViewById(R.id.listview);

        // Prepare ListView Item Click Listener
        noteListView.setOnItemClickListener(viewNoteListener);

        // Map all the titles into the ViewTitleNotes TextView
        String[] from = new String[] { TITLE };
        int[] to = new int[] { R.id.ViewTitleNotes };

        // Create a SimpleCursorAdapter
        noteAdapter = new SimpleCursorAdapter(dbMainactivty.this,
                R.layout.list_note, null, from, to);

        // Set the Adapter into SimpleCursorAdapter
        setListAdapter(noteAdapter);
    }

    // Capture ListView item click
    OnItemClickListener viewNoteListener = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {

            // Open ViewNote activity
            Intent viewnote = new Intent(dbMainactivty.this, ViewNote.class);

            // Pass the ROW_ID to ViewNote activity
            viewnote.putExtra(ROW_ID, arg3);
            startActivity(viewnote);
        }
    };

    @Override
    protected void onResume() {
        super.onResume();

        // Execute GetNotes Asynctask on return to MainActivity
        new GetNotes().execute((Object[]) null);
    }

    @Override
    protected void onStop() {
        Cursor cursor = noteAdapter.getCursor();

        // Deactivates the Cursor
        if (cursor != null)
            cursor.deactivate();

        noteAdapter.changeCursor(null);
        super.onStop();
    }

    // Create an options menu
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Menu Title
//      menu.add("Add New Notes")
//              .setOnMenuItemClickListener(this.AddNewNoteClickListener)
//              .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        return super.onCreateOptionsMenu(menu);
    }

    // Capture menu item click
    OnMenuItemClickListener AddNewNoteClickListener = new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {

            // Open AddEditNotes activity
            Intent addnote = new Intent(dbMainactivty.this, AddEditNotes.class);
            startActivity(addnote);

            return false;

        }
    };

    // GetNotes AsyncTask
    private class GetNotes extends AsyncTask<Object, Object, Cursor> {
        DatabaseConnector dbConnector = new DatabaseConnector(dbMainactivty.this);

        @Override
        protected Cursor doInBackground(Object... params) {
            // Open the database
            dbConnector.open();

            return dbConnector.ListAllNotes("maincat LIKE 'quiz' AND subcat LIKE 'test'");
        }

        @Override
        protected void onPostExecute(Cursor result) {
            noteAdapter.changeCursor(result);

            // Close Database
            dbConnector.close();
        }
    }
}
我认为listview可以解决我的问题,但我是android新手,不知道如何用CuroraAdapter实现listview

如何在上面的代码中实现


如果我用listview扩展actionbar活动,它能工作吗?

相反,ListActivity使用ActionBarActivity+ListFragments从v4 compat。。。关于创建代码移到onViewCreated的提示很少。。。任何活动方法的使用都将成为getAvtivity.activityPublicMethod。。。而不是活动上下文使用getActivity。。。一旦CreateOptions菜单中的片段稍有不同,我的代码就太复杂了,不能使用listfragmentsyes,你可以。除了懒惰之外,没有其他原因可以阻止您重构所有代码并使用片段。。。在java中没有多类继承。。。因此,另一种选择是从原始ListActivity.javaandroid源代码或v4 compat库复制代码,并使其扩展ActionBarActivity而不是Activity。。。更好的选择是使用片段