Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wanted to do the same with this example. There are several places where alterations are required to make it work with the support library. Here's my complete java file with the changes highlighted in the comments: </p> <pre><code>package com.paad.todolist; import java.util.ArrayList; import android.support.v4.app.FragmentActivity; // Because we're using the support library // version of fragments, the import has to be // FragmentActivity rather than Activity import android.support.v4.app.FragmentManager; // Support version of Fragment Manager import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; // because we're using the support library version of fragments, the class has to extend the // FragmentActivity superclass rather than the more usual Activity superclass public class ToDoListActivity extends FragmentActivity implements NewItemFragment.OnNewItemAddedListener { // logging tag private static final String TAG = "ToDoListActivity"; // create an array adaptor ready to bind the array to the list view private ArrayAdapter&lt;String&gt; aa; // set up array list to hold the ToDo items private ArrayList&lt;String&gt; todoItems; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "The onCreate method has started"); // inflate the view setContentView(R.layout.activity_to_do_list); // get references to the fragments // FragmentManager fm = getFragmentManager(); this won't work with the support library version FragmentManager fm = getSupportFragmentManager(); // this is the equivalent for support library ToDoListFragment todoListFragment = (ToDoListFragment)fm.findFragmentById(R.id.ToDoListFragment); // Create the array list of to do items todoItems = new ArrayList&lt;String&gt;(); // Create the array adapter to bind the array to the listview aa = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, todoItems); // bind the array adapter to the list view todoListFragment.setListAdapter(aa); } // implement the listener... It adds the received string to the array list // then notifies the array adapter of the dataset change public void onNewItemAdded(String newItem) { todoItems.add(newItem); aa.notifyDataSetChanged(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload