package com.c2.layoutsdemo;
import java.util.ArrayList;
import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class ToDoListActivity extends Activity implements NewItemFragment.OnNewItemAddedListener {
此外,如果我按照示例将arraylist 和addar 适配器设为final,我会收到有关arraylist 初始化的其他错误。
ArrayList<String> todoItems;
ArrayAdapter<String> aa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_to_do_list);
FragmentManager fm= getFragmentManager();
ToDoListFragment todolistFragment = (ToDoListFragment)fm.findFragmentById(R.layout.ToDoListFragment);
上面的行给出错误:ToDoListFragment 无法解析或不是字段
todoItems = new ArrayList<String>();
aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,todoItems);
todolistFragment.setListAdapter(aa);
}
@Override
public void onNewItemAdded(String newItem) {
todoItems.add(newItem);
aa.notifyDataSetChanged();
}
}