I have a tab activity with a listview, which makes a query json. When I test it in the emulator everything works fine, however in some devices the listview is not displayed, which may be happening?
This is my Res / Layout / movements
<TabHost
android:id="@+id/tabcontainer"
android:theme="@style/TabWidgetTheme"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF812899" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/IngresosLayout"
layout="@layout/listado_de_ingresos"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/PagosLayout"
layout="@layout/listado_de_egresos">
</include>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
import android.app.ProgressDialog;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class Movimientos extends Fragment {
ArrayList<HashMap<String, String>> IngresoList, EgresoList;
private ListView lv, li;
RequestQueue requestQueue;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_movimientos, container, false);
((MainActivity) getActivity()).hideFloatingActionButton();
//Resources res = getResources();
IngresoList = new ArrayList<>();
EgresoList = new ArrayList<>();
lv = (ListView) view.findViewById(R.id.listaegresos);
li = (ListView) view.findViewById(R.id.listaingresos);
requestQueue = Volley.newRequestQueue(getActivity());
final TabHost tabs = (TabHost)view.findViewById(R.id.tabcontainer);
tabs.setup();
TabHost.TabSpec spec = tabs.newTabSpec("tab1");
spec.setContent(R.id.IngresosLayout);
spec.setIndicator("e-Pay Enviados");
tabs.addTab(spec);
TabHost.TabSpec spec2 = tabs.newTabSpec("tab2");
spec2.setContent(R.id.PagosLayout);
spec2.setIndicator("e-Pay Recibidos");
tabs.addTab(spec2);
tabs.setCurrentTab(0);
tabs.getTabWidget().getChildAt(tabs.getCurrentTab()).setBackgroundColor(Color.parseColor("#FF9533AF")); // selected
tabs.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
for (int i = 0; i < tabs.getTabWidget().getChildCount(); i++) {
tabs.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FF812899")); // unselected
TextView tv = (TextView) tabs.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
tv.setTextColor(Color.parseColor("#ffffff"));
}
tabs.getTabWidget().getChildAt(tabs.getCurrentTab()).setBackgroundColor(Color.parseColor("#FF9533AF")); // selected
TextView tv = (TextView) tabs.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab
tv.setTextColor(Color.parseColor("#ffff00"));
}
});
getDataMovEntrada();
getDataMovSalida();
return view;
}
private void getDataMovSalida() {
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle("Estamos procesando la transacción");
progressDialog.setMessage("Aguarda un momento");
progressDialog.setCancelable(true);
progressDialog.show();
final String Usercorreo = Constantes.CORREO;
MovRequest movRequest = new MovRequest(Usercorreo, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("Pago Response", response);
progressDialog.dismiss();
//JSONObject jsonObject=null;
try {
JSONObject jsonObject = new JSONObject(response);
// Getting JSON Array node
JSONArray movimientos = jsonObject.getJSONArray("movimientos");
// looping through All Contacts
for (int i=0; i < movimientos.length(); i++) {
JSONObject c = movimientos.getJSONObject(i);
String id=c.getString("idTrans");
String comercioName=c.getString("P.NOMBRE");
String comercioRif=c.getString("P.RIF");
String comercioLogo=c.getString("IMGPERFIL");
String fmonto=c.getString("monto");
String monto = fmonto +" +" ;
String fecha=c.getString("fecha");
String concepto=c.getString("concepto");
String Norecibo ="No. de control: " + id;
HashMap<String, String> egresos = new HashMap<>();
egresos.put("id", Norecibo);
egresos.put("comercio", comercioName);
egresos.put("rif", comercioRif);
egresos.put(Constantes.TRANSACCION_COMERCIO_LOGO, comercioLogo);
egresos.put("monto", monto);
egresos.put("fecha", fecha);
egresos.put("concepto", concepto);
EgresoList.add(egresos);
//Toast.makeText(getActivity(), "Estoy aqui", Toast.LENGTH_LONG).show();
}
ListAdapter adapter =
new MyMovAdapter(
getActivity(),
EgresoList,
R.layout.lista_egresos,
new String[]{"comercio", "rif","monto", "fecha", "concepto", "id"},
new int[]{R.id.txtCOMERCIOnombre,
R.id.txtCOMERCIOrif, R.id.txtMOVmonto, R.id.txtMOVfecha, R.id.txtMOVconcepto, R.id.txtMOVid});
lv.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
requestQueue.add(movRequest);
}
private void getDataMovEntrada() {
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle("Estamos procesando la transacción");
progressDialog.setMessage("Aguarda un momento");
progressDialog.setCancelable(true);
progressDialog.show();
final String Usercorreo = Constantes.CORREO;
MovxRequest movxRequest = new MovxRequest(Usercorreo, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("Pago Response", response);
progressDialog.dismiss();
//JSONObject jsonObject=null;
try {
JSONObject jsonObject = new JSONObject(response);
// Getting JSON Array node
JSONArray xmovimientos = jsonObject.getJSONArray("movimientos");
// looping through All Contacts
for (int i=0; i < xmovimientos.length(); i++) {
JSONObject xc = xmovimientos.getJSONObject(i);
String xid=xc.getString("idTrans");
String xcomercioName=xc.getString("P.NOMBRE");
String xcomercioRif=xc.getString("P.RIF");
String xcomercioLogo=xc.getString("IMGPERFIL");
String xfmonto=xc.getString("monto");
String xmonto = xfmonto +" -" ;
String xfecha=xc.getString("fecha");
String xconcepto=xc.getString("concepto");
String xNorecibo ="No. de control: " + xid;
HashMap<String, String> ingresos = new HashMap<>();
ingresos.put("xid", xNorecibo);
ingresos.put("xcomercio", xcomercioName);
ingresos.put("xrif", xcomercioRif);
ingresos.put(Constantes.TRANSACCION_COMERCIO_LOGOX, xcomercioLogo);
ingresos.put("xmonto", xmonto);
ingresos.put("xfecha", xfecha);
ingresos.put("xconcepto", xconcepto);
IngresoList.add(ingresos);
}
ListAdapter adapter =
new MyMovxAdapter(
getActivity(),
IngresoList,
R.layout.lista_exgresos,
new String[]{"xcomercio", "xrif","xmonto", "xfecha", "xconcepto", "xid"},
new int[]{R.id.txtCOMERCIOnombre,
R.id.txtCOMERCIOrif, R.id.txtMOVmonto, R.id.txtMOVfecha, R.id.txtMOVconcepto, R.id.txtMOVid});
li.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
requestQueue.add(movxRequest);
}
}
Now, in devices versions> 5.0.3 it looks good, in 5.0.1 no, not to say previous versions because the app crashed me