Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're trying to pass that <code>myLong</code> value through the <code>Callbacks</code> interface to the <code>DetailsFragment</code> you're not doing it right. The idea of that callback is for someone to implement it and register itself as a listener so when the user clicks the list item that implementation is called(and not just have an empty implementation which will not do anything). You could leave the communication between the fragments for the activity which shows those fragments to manage. For example:</p> <pre><code>public class CustomerListFragment extends ListFragment { private Callbacks mCallbacks; public interface Callbacks { public void onItemSelected(String id); } @Override public void onAttach(Activity activity) { super.onAttach(activity); try { mCallbacks = (Callbacks) activity; } catch (ClassCastException ex) { Log.e(TAG, "Casting the activity as a Callbacks listener failed" + ex); mCallbacks = null; } } @Override public void onListItemClick(ListView listView, View view, int position, long id) { long myLong = values.get(position).getId(); if (mCallbacks != null) { mCallbacks.onItemSelected(myLong); } } // ... </code></pre> <p>And then in your activity which holds the two fragments:</p> <pre><code>public class MainActivity extends FragmentActivity implements CustomerListFragment.Callbacks { // ... public void onItemSelected(Long id) { Bundle arguments = new Bundle(); arguments.putLong(CustomerDetailFragment.ARG_ITEM_ID, id); CustomerDetailFragment fragment = new CustomerDetailFragment(); fragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() .replace(R.id.customer_detail_container, fragment) .commit(); } //... </code></pre> <p>And then retrieve the id from the arguments passed to the <code>CustomerDetailFragment</code> :</p> <pre><code>long theId = -1; if (getArguments().containsKey(ARG_ITEM_ID)) { theId = getArguments().getLong(ARG_ITEM_ID)); } selectedCustomer = datasource.getCustomer(theId); </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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