Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually if you see your code closly there's a method that you have mention</p> <pre><code>public void setListAdapter() { array = getResources().getStringArray(R.array.jazz_artist_names); list = new ArrayList&lt;String&gt;(Arrays.asList(array)); adapter = new ArrayAdapter&lt;String&gt;(getActivity(), getItemLayout(), R.id.text, list); setListAdapter(adapter); } </code></pre> <p>So as you said : "generally we create new adapter and pass it to listview like lv.setAdapter(adapter) , but here they just set ListAdapter, so we cant do lv.setAdapter(adapter)"</p> <p>Can't you easily do this by easily generating an array based on your search and set it like the code ??</p> <pre><code>list = new ArrayList&lt;String&gt;(Arrays.asList(array)); adapter = new ArrayAdapter&lt;String&gt;(getActivity(), getItemLayout(), R.id.text, list); setListAdapter(adapter); </code></pre> <p>EDIT: I think you are asking the wrong question. Your main concern should be how to communicate between activity and fragments...since your search functionality is in activity and list is in fragment. So you need to setup an interface that basically passes on the search string to your fragment and there you can make an array and set it the same way you are doing right now.</p> <p>Read <a href="https://stackoverflow.com/questions/13620711/how-to-pass-data-from-activity-to-fragment">this</a> SO question and answer. In the answer you'll find one similar approach on passing data between activity and fragment.</p> <p>Edit 2: Your main concern is to communicate from activity to fragment for this..declare an interface in your activity like this:</p> <pre><code> public interface FragmentCommunicator{ public void passDataToFragment(String someValue); } then call the interface at your text change listener..for example FragmentCommunicator mfragmentCommunicator; //your onCreate function { //your textchangelistenr { onTextChanged call if(mfragmentCommunicator != null) mfragmentCommunicator.passDataToFragment(Pass your string here) } then make your fragement implement this interface like public class someFragment extends Fragment implements FragmentCommunicator { //this is your rest of the fragment @Override public void passDataToFragment(String somevalue) { //This function will get fired each time your text is changed since in your activity you are calling this same function in your textchange listener. the String somevalue will be the string that you passed from your activity } //rest of the code . . . //Don't forget to initialize your interface in fragment itself. Do this in your onAttach like this @Override public void onAttach(Activity activity){ super.onAttach(activity); context = getActivity(); ((MainActivity)context).fragmentCommunicator = this; } } } </code></pre> <p>You can refer <a href="http://laaptu.wordpress.com/tag/android-communication-between-fragment-and-activity/" rel="nofollow noreferrer">this</a> link for any further clarifications. Check only the implementation of FragmentCommunicator</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