0
I have a screen that searches by name through an Edittext. And when searching by name it brings me a Recycleview with its results. And when I touch an element of the result, it goes to a Fragment (another screen). Only that I wanted to pass the data of the element that was played when opening the Fragment (the Fragment already opens, just does not receive the data yet). i wanted to pass the "teacher" field to another Fragment. Can someone give a force ? Below an excerpt of Json with the Fragment call:
public static consultarListaNome newInstance(String param1, String param2) {
consultarListaNome fragment = new consultarListaNome();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
public void onResponse(JSONObject response) {
progresso.hide();
Curso curso = null;
JSONArray json = response.optJSONArray("curso"); // nome da tabela curso
try {
for(int i=0; i<json.length();i++){
curso = new Curso();
JSONObject jsonObject = null;
jsonObject = json.getJSONObject(i);
curso.setNome(jsonObject.optString("nome"));
curso.setProfessor(jsonObject.optString("professor"));
curso.setCategoria(jsonObject.optString("categoria"));
curso.setDado(jsonObject.optString("imagem"));
listaCursos.add(curso);
}
progresso.hide();
CursosAdapterImg adapter = new CursosAdapterImg(listaCursos,getContext(),this);
recyclerCursos.setAdapter(adapter);
}catch (JSONException e){
e.printStackTrace();
progresso.hide();
Toast.makeText(getContext(), "Não foi possível listar os cursos " +response , Toast.LENGTH_SHORT).show();
}
}
This section below calls the other Fragment:
@Override
public void onNoteClick(int position) {
listaCursos.get(position);
//Falta passar os parâmetros
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_main,new consultarCursoUrl()).commit();
}
It wasn’t quite what I wanted, but at least I’ve learned to pass parameters through Ragments. I could get close. I think I explained myself badly. When I do the search, it returns me the items in the recycleview. The recycleview consists of textview (there is the teacher field) and an image. Dae interests me to take an item from this textview.
– Luciana Freire Efelipe Correia