ListView not populated in all tabs on the first access [closed]

1

Hello, I have an Android application for an electronic questionnaire. The same questionnaire should be presented in tabs, they are 7 tabs. The application lowers the web issues of an XML.

I am using the Volley library to access the questionnaire. When I go down the questionnaire and parse the XML record in the database and then display it in a ListView.

The problem is that issues do not appear in the first two tabs. They appear from the third. And when accessing the third one the questions appear in the first one and when accessing the fourth they appear in the second one. The others work normally.

The code for the fragments are these:

public class MainActivity extends FragmentActivity {

//declarações e onCreate...


private void requestQuestionario(){
    String tag_string_req = "req_questionario"; //tag para cancelar o request

    pDialog.setMessage("Carregando Questionário...");
    showDialog();

    StringRequest stringRequest = new StringRequest(Request.Method.GET,
            RequestContract.XMLQuestionarioContract.XML_QUESITIONARIO_URL, new Response.Listener<String>() {

        @Override
        public void onResponse(String s) {
            Log.d(TAG, "Response = " + s);

            //TODO -- Tratar Response
            InputStream xml = new ByteArrayInputStream(s.getBytes());
            try {
                HashMap questionario = XmlParser.parse(xml);
                List<Questao> questoes = (List) questionario.get("questoes");

               //insere questoes no banco....


                QuestionarioCache cache = QuestionarioCache.newInstance();
                cache.setQuestoes(questoes);


                cache.getAdapter(getApplication()).notifyDataSetChanged();


            } catch (XmlPullParserException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (SQLException e){
                e.printStackTrace();
            }

            hideDialog();
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {

           //Carrega as questões existentes no banco....
        }
    });

    requestQueue = RequestManager.getInstance(this).getRequestQueue();

    stringRequest.setTag(tag_string_req);
    requestQueue.add(stringRequest);
}


}

Fragment with ListView

public class ListaQuestoesActivity extends Fragment {
private static final String TAG = ListaQuestoesActivity.class.getSimpleName();

private View v;
private TextView textView;
private ListView listView;

private QuestionarioCache cache;

private int dia;

// onCreate....

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.fragment_lista_questoes, container, false);

    textView = (TextView) v.findViewById(R.id.txt_dia_qionario);
    textView.setText("Dia " + dia);

    carregarListaQuestoes();

    return v;

}


private void carregarListaQuestoes(){
    listView = (ListView) v.findViewById(R.id.list_questoes);

    cache = QuestionarioCache.newInstance();

    listView.setAdapter(cache.getAdapter(getActivity()));


}
}

When I use a static list it usually appears in all tabs:

String[] list = {"Ola", "Mundo", "Foo", "Bar"};

    ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, list);

    listView.setAdapter(adapter);

Does anyone know how to fix it?

    
asked by anonymous 18.09.2015 / 23:13

0 answers