Note that there are some explanatory texts on larger screens.

plurals
  1. PORefreshing my fragment not working like I thought it should
    text
    copied!<p>I have this nice method in my ListFragment I call to fill out the details of my other fragment:</p> <pre><code>private void showClientDetails(int pos) { myCursor.moveToPosition(pos); int clientId = myCursor.getInt(0); if(mIsTablet) { // Set the list item as checked getListView().setItemChecked(mCurrentSelectedItemIndex, true); // Get the fragment instance ClientDetails details = (ClientDetails) getFragmentManager().findFragmentById(R.id.client_details); // Is the current visible recipe the same as the clicked? If so, there is no need to update if (details == null || details.getClientIndex() != mCurrentSelectedItemIndex) { // Make new fragment instance to show the recipe details = ClientDetails.newInstance(mCurrentSelectedItemIndex, clientId, mIsTablet); // Replace the old fragment with the new one FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.client_details, details); // Use a fade animation. This makes it clear that this is not a new "layer" // above the current, but a replacement ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); } } } </code></pre> <p>It is called when the user clicks on a client in the ListFragment view:</p> <pre><code>@Override public void onListItemClick(ListView l, View v, int position, long id) { mCurrentSelectedItemIndex = position; showClientDetails(position); } </code></pre> <p>This works great, but then another FragmentActivity can change the data that this displays so I thought this would work:</p> <pre><code>@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //update the client list incase a new one is added or the name changes if(requestCode==1899) { myCursor.requery(); theClients.notifyDataSetChanged(); showClientDetails(mCurrentSelectedItemIndex); //now if client was edited update their details in the details fragment } } </code></pre> <p>Now I know the line:</p> <p><code>if (details == null || details.getClientIndex() != mCurrentSelectedItemIndex) {</code></p> <p>Prevents the block of code being reached when its called in my onActivityResult. So if I remove that <code>if</code> statement, then things freak out and the ft.commit() has a hissy fit and gives me the error:</p> <p>`07-08 16:53:31.783: ERROR/AndroidRuntime(2048): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState</p> <p>So I guess what I am trying to do isn't as cut and dry as it sounds, it makes no sense to me since I can do that onListItemClicked all day and the fragment displays the details of the newly clicked client constantly very well...</p> <p>I even tried this in my <code>onActivityResult</code>:</p> <pre><code>//simulate a click event really fast to refresh the client details showClientDetails(0); showClientDetails(mCurrentSelectedItemIndex); </code></pre> <p>that does nothing, is it im trying to call something from the onActivityResult which isn't a Ui thread or what not?</p> <p>I do have this in my code of the ListFragment as well</p> <pre><code>@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("currentListIndex", mCurrentSelectedItemIndex); } </code></pre> <p>Is this what the error is complaining about?</p>
 

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