Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's how I solved my problem. Seem's you must include setListAdapter() in either onCreate() or onActivityCreated(). Code for future reference:</p> <pre><code>public class PlayersListFragment extends ListFragment { OnPlayerSelectedListener mCallback; // URL to make request private static String URL = Utils.URL; private static int userID; ArrayList&lt;HashMap&lt;String, Object&gt;&gt; playersList; ListView playerView; private ProgressDialog pDialog; // The container Activity must implement this interface so the frag can // deliver messages public interface OnPlayerSelectedListener { /** Called by HeadlinesFragment when a list item is selected */ public void onPlayerSelected(int position); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); initLayout(); new PlayersLoadTask().execute(); int layout = Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB ? android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1; setListAdapter(new PlayerListAdapter(getActivity(), layout, playersList)); } public boolean onOptionsItemSelected(MenuItem item) { return false; } private void initLayout() { if(getActivity().getIntent()!=null) { userID = getActivity().getIntent().getIntExtra("id", 0); } else { return; } playerView = getListView(); playersList = new ArrayList&lt;HashMap&lt;String, Object&gt;&gt;(); } @Override public void onStart() { super.onStart(); // When in two-pane layout, set the listview to highlight the selected // list item // (We do this during onStart because at the point the listview is // available.) if (getFragmentManager().findFragmentById(R.id.playerDetailFragment) != null) { playerView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } } @Override public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception. try { mCallback = (OnPlayerSelectedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnPlayerSelectedListener"); } } @Override public void onListItemClick(ListView l, View v, int position, long id) { // Notify the parent activity of selected item mCallback.onPlayerSelected(position); // Set the item as checked to be highlighted when in two-pane layout playerView.setItemChecked(position, true); } class PlayersLoadTask extends AsyncTask&lt;String, String, String&gt; { @Override protected void onPreExecute() { pDialog = ProgressDialog.show(getActivity(), "", "Loading. Please wait...", true); } @Override protected String doInBackground(String... params) { try { ArrayList&lt;BasicNameValuePair&gt; parameters = new ArrayList&lt;BasicNameValuePair&gt;(); parameters.add(new BasicNameValuePair("request", "getPlayers")); parameters.add(new BasicNameValuePair("clubid", Integer .toString(userID))); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(URL); httpPost.setEntity(new UrlEncodedFormEntity(parameters, ("ISO-8859-1"))); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); // if this is null the web service returned an empty page if (httpEntity == null) // response is empty so exit out return null; String jsonString = EntityUtils.toString(httpEntity); if (jsonString != null &amp;&amp; jsonString.length() != 0) { JSONArray jsonArray = new JSONArray(jsonString); for (int i = 0; i &lt; jsonArray.length(); i++) { HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;(); JSONObject jsonObject = (JSONObject) jsonArray.get(i); int id = jsonObject.getInt("id"); String name = jsonObject.getString("name"); map.put("id", id); map.put("name", name); playersList.add(map); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { Log.e("ERROR SOMEWHERE!!!! ", e.toString()); } return null; } @Override protected void onPostExecute(String file_url) { if (pDialog.isShowing()) pDialog.dismiss(); if (playersList.size() == 0) { Toast.makeText(getActivity(), "No players in a list", Toast.LENGTH_SHORT).show(); } else if(playerView != null) { setListAdapter(new PlayerListAdapter(getActivity(), R.id.player_list_id, playersList)); /*playerView.setAdapter(new PlayerListAdapter( getActivity(), R.id.player_list_id, playersList));*/ } } } </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.
 

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