Wednesday, 28 August 2013

Hi i'm a android begineer. Was just going through an example and the rest of the project is fine just an error While using fragment manager

Hi i'm a android begineer. Was just going through an example and the rest
of the project is fine just an error While using fragment manager

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 {
// 1- also if i make arraylist and addar adapter final as per example, i
get additinal errors regarding initialization of arraylist.
ArrayList todoItems; ArrayAdapter 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);
// 2- The above line gives error : ToDoListFragment cannot be resolved or
is not a field
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();
}
}

No comments:

Post a Comment