I'm reading two xml with two different structures, I can populate a RecyclerView with the two adapters of each xml.
In this picture you can see what I want to do.
Now I have the files that are for a parser xml, a class for each xml, a parser for each, an adapter for each one, what I do not know, if you can join them in the fragment class where I load the data and the charge in the recyvlerView.
This is the fragment code I was using but I get an error and the application is closed
public class fqsomos extends Fragment{
private RecyclerView reciclador,recicladorNosotros;
private LinearLayoutManager layoutManager;
private adaptadorQsomos adaptador;
private adaptadorNosotros adaptadorNosotros;
private CircularProgressView loader ;
private SwipeRefreshLayout refreshLayout;
ProgressDialog loading = null;
private ProgressBar spinner;
private ProgressBar spinnerNosotros;
private final static String URL ="http://svconstructions.com.ec/sv/qsomosapp.php";
private final static String URL_nosotros ="http://svconstructions.com.ec/sv/qsomosapp.php";
private static final String LOGTAG = "LogsProyectos";
final Activity activity = getActivity();
public fqsomos() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.lqsomos, container, false);
reciclador = (RecyclerView) view.findViewById(R.id.reciclador);
recicladorNosotros = (RecyclerView) view.findViewById(R.id.recicladorNosotros);
layoutManager = new LinearLayoutManager(getActivity());
reciclador.setLayoutManager(layoutManager);
recicladorNosotros.setLayoutManager(layoutManager);
spinner = (ProgressBar)view.findViewById(R.id.progressbarqsomos);
spinnerNosotros = (ProgressBar)view.findViewById(R.id.progressbarNosotros);
adaptador = new adaptadorQsomos();
adaptador.setHasStableIds(true);
//spinner.setVisibility(View.GONE );
reciclador.setAdapter(adaptador);
// recicladorNosotros.setAdapter(adaptadorNosotros);
new TareaDescargaXml_Qsomos().execute(URL);
// new TareaDescargaXml_Nosotros().execute(URL_nosotros);
return view;
}
public class TareaDescargaXml_Qsomos extends AsyncTask<String, Void, List<qsomo>> {
@Override
protected void onPreExecute() {
// show the progress bar
// spinner.setVisibility(View.VISIBLE);
}
@Override
protected List<qsomo> doInBackground(String... urls) {
try {
return parsearXmlDeUrl(urls[0]);
} catch (IOException e) {
Log.e( LOGTAG,"Error en la red",e);
return null; // null si hay error de red
} catch (XmlPullParserException e) {
Log.e( LOGTAG,"Error al leer xml",e);
return null; // null si hay error de parsing XML
}
}
@Override
protected void onPostExecute(List<qsomo> result) {
spinner.setVisibility(View.GONE );
// Actualizar contenido del proveedor de datos
qsomo.Ultimas_qsomos = result;
// Actualizar la vista del adaptador
adaptador.notifyDataSetChanged();
}
}
private List<qsomo> parsearXmlDeUrl(String urlString)
throws XmlPullParserException, IOException {
InputStream stream = null;
parseQsomos parserXml = new parseQsomos();
List<qsomo> entries = null;
try {
stream = descargarContenido(urlString);
entries = parserXml.parsear(stream);
} finally {
if (stream != null) {
stream.close();
}
}
return entries;
}
// nosotros
//***************--------------------------------------*******************
public class TareaDescargaXml_Nosotros extends AsyncTask<String, Void, List<nosotro>> {
@Override
protected void onPreExecute() {
// show the progress bar
// spinner.setVisibility(View.VISIBLE);
}
@Override
protected List<nosotro> doInBackground(String... urls) {
try {
return parsearXmlDeUrlNosotros(urls[0]);
} catch (IOException e) {
Log.e( LOGTAG,"Error en la red",e);
return null; // null si hay error de red
} catch (XmlPullParserException e) {
Log.e( LOGTAG,"Error al leer xml",e);
return null; // null si hay error de parsing XML
}
}
@Override
protected void onPostExecute(List<nosotro> result) {
spinnerNosotros.setVisibility(View.GONE );
// Actualizar contenido del proveedor de datos
nosotro.Listado_nosotros = result;
// Actualizar la vista del adaptador
adaptadorNosotros.notifyDataSetChanged();
}
}
private List<nosotro> parsearXmlDeUrlNosotros(String urlString)
throws XmlPullParserException, IOException {
InputStream stream = null;
parseNosotros parserXml = new parseNosotros();
List<nosotro> entries = null;
try {
stream = descargarContenido(urlString);
entries = parserXml.parsear(stream);
} finally {
if (stream != null) {
stream.close();
}
}
return entries;
}
private InputStream descargarContenido(String urlString) throws IOException {
java.net.URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
// Iniciar la petición
conn.connect();
return conn.getInputStream();
}
}
and in the Layout of this fragment I have two recyclerView.