Result result = getItem(position); setUpResultTextView(textViewQuery, result.getTextQuery()); setUpResultTextView(textViewAnswer, result.getTextAnswer());
/** * Update the listView and scroll to the bottom * @param instantScroll if false, use animated scroll to bottom, * otherwise use scroll instantly */ public void refresh(boolean instantScroll) { if (getListAdapter() == null) return; //notify the adapter that the listview needs to be updated ((ResultAdapter) getListAdapter()).notifyDataSetChanged(); //scroll to the bottom of the list if (instantScroll){ //post a runnable for setSelection otherwise it won't be called getListView().post(new Runnable() { @Override public void run() { //attempt to fix bug: if (getListAdapter() == null) return; // try { getListView().setSelection(getListAdapter().getCount() - 1); // } catch (IllegalStateException e) { // } } }); } else getListView().smoothScrollToPosition(getListAdapter().getCount() - 1); } }
/** * Called when the fragment's activity has been created and this * fragment's view hierarchy instantiated. It can be used to do final * initialization once these pieces are in place, such as retrieving * views or restoring state. It is also useful for fragments that use * {@link #setRetainInstance(boolean)} to retain their instance, * as this callback tells the fragment when it is fully associated with * the new activity instance. This is called after {@link #onCreateView} * and before {@link #onViewStateRestored(Bundle)}. * * @param savedInstanceState If the fragment is being re-created from * a previous saved state, this is the state. */ @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mResultArray = Calculator.getCalculator(getActivity()).getResultList(); ResultAdapter adapter = new ResultAdapter(mResultArray); setListAdapter(adapter); }