Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to preserve searched data on coming back from another fragment
    primarykey
    data
    text
    <p>I have two fragments(A &amp; B). In fragment A, I have two edit boxes and a search button.</p> <p>Upon click of search button, I am populating a list view with searched results below the button. On list item click, I am passing values using bundle to fragment B using below code:</p> <pre><code>FragmentB details = new FragmentB(); Bundle detailsBundle = new Bundle(); detailsBundle.putString("ProdCode", _prodCode); detailsBundle.putString("ProdName", _prodName); detailsBundle.putString("UnitPrice", _unitPrice); detailsBundle.putString("StockValue", _stockValue); detailsBundle.putString("Indicator", _indicator); detailsBundle.putString("OpenOrderValue", _openOrderValue); detailsBundle.putString("OpenInvoiceValue", _openInvoiceValue); details.setArguments(detailsBundle); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.container, details, "Details"); ft.addToBackStack(null); ft.commit(); </code></pre> <p>But when I click back button on Fragment B, populated list in fragment A getting disappeared. How can I preserve the searched results in listview and also how can I clear the text from the edit boxes on coming back from fragment B to fragment A.</p> <p>[Edit]</p> <pre><code>public class MainActivity extends Activity implements OnClickListener { private Button button1, button2, button3, button4; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); button1 = (Button) findViewById(R.id.btnFrgament1); button2 = (Button) findViewById(R.id.btnFrgament2); button3 = (Button) findViewById(R.id.btnFrgament3); button4 = (Button) findViewById(R.id.btnFrgament4); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); FirstFragment initialFragment = new FirstFragment(); ft.add(R.id.containerLinearLayout, initialFragment); ft.commit(); button1.setOnClickListener(this); button2.setOnClickListener(this); button3.setOnClickListener(this); button4.setOnClickListener(this); } @Override public void onClick(View v) { Fragment newFragment; int id = v.getId(); switch(id) { case R.id.btnFragment1: newFragment = new FirstFragment(); break; case R.id.btnFragment2: newFragment = new SecondFragment(); break; case R.id.btnFragment3: newFragment = new ThirdFragment(); break; case R.id.btnFragment4: newFragment = new FourthFragment(); break; default: newFragment = new FirstFragment(); break; } FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.containerLinearLayout, newFragment); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.commit(); } </code></pre> <p>SecondFragment has two edit boxes and a button(Search). I am displaying searched results in listview below button. When I click on list item, I am passing details to next fragment using the bundle as shown above. When I come back by hitting back button from details fragment to previous fragment, list getting disappeared.</p>
    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. 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