我可以在 ActionBarActivity 中动态填充 ListView 吗?

Can I dynamically populate a ListView in an ActionBarActivity?

我看到了许多在 ListActivity 中填充 ListView 的示例。我想要一个动态填充的 ListView,但在一个带有操作栏的 activity 中。

所以而不是(如我所见的例子):

public class EditHolidaysActivity extends ListActivity {

我有:

public class EditHolidaysActivity extends ActionBarActivity {

但是无法解析setListAdapter方法。我可以使用什么方法来填充 ListView?以下是 xml 和 java 的片段:

    ...
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Anni"
        android:id="@+id/chkbxAnniversary"
        android:checked="false"
        android:onClick="saveAnniPref"/>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

Java:

public class EditHolidaysActivity extends ActionBarActivity {
    public static final String PREFS_NAME = MainActivity.PREFS_NAME;
    private final static String TEXT_DATA_KEY = "textData";
    private CommentsDataSource datasource;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_holidays);

        datasource = new CommentsDataSource(this);
        datasource.open();

        List<Comment> values = datasource.getAllComments();

        // use the SimpleCursorAdapter to show the
        // elements in a ListView
        ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
                android.R.layout.simple_list_item_1, values);
        setListAdapter(adapter);
    }

谢谢!

像这样:

public class EditHolidaysActivity extends ActionBarActivity {
public static final String PREFS_NAME = MainActivity.PREFS_NAME;
private final static String TEXT_DATA_KEY = "textData";
private CommentsDataSource datasource;
private ListView lstView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_holidays);

    lstView = (ListView)findViewById(R.id.list);

    datasource = new CommentsDataSource(this);
    datasource.open();

    List<Comment> values = datasource.getAllComments();

    // use the SimpleCursorAdapter to show the
    // elements in a ListView
    ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
            android.R.layout.simple_list_item_1, values);
    lstView.setAdapter(adapter);
}