I have this ListView adapter:
public class UpicksAdapter extends BaseAdapter
{
Context context;
List<Upick> upick_list;
public UpicksAdapter(List<Upick> listValue, Context context)
{
this.context = context;
this.upick_list = listValue;
}
#Override
public int getCount()
{
return this.upick_list.size();
}
#Override
public Object getItem(int position)
{
return this.upick_list.get(position);
}
#Override
public long getItemId(int position)
{
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewItem viewItem = null;
if(convertView == null)
{
viewItem = new ViewItem();
LayoutInflater layoutInfiater = (LayoutInflater)this.context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutInfiater.inflate(R.layout.listview_items, null);
viewItem.SubNameTextView = (TextView)convertView.findViewById(R.id.SubjectNameTextView);
viewItem.SubFullFormTextView = (TextView)convertView.findViewById(R.id.SubjectFullFormTextView);
convertView.setTag(viewItem);
}
else
{
viewItem = (ViewItem) convertView.getTag();
}
viewItem.SubNameTextView.setText(upick_list.get(position).Subject_Name);
viewItem.SubFullFormTextView.setText(upick_list.get(position).Subject_Full_Form);
return convertView;
}
}
class ViewItem
{
TextView SubNameTextView;
TextView SubFullFormTextView;
}
The ListView is in a fragment.
I need to get data from the listview selected item. I have this listener:
UpicksListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String item = UpicksListView.getItemAtPosition(position).toString();
Log.d("VALOR","VALOR "+item);
}
});
How can I get the values of the selected item?
EDIT:
Complete Fragment code:
public class MisUpicksFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private SessionManager session;
private ProgressDialog loading;
private EditText txtbusqueda;
private Button botonbuscar,botonrefrescar;
//movies
private static final String TAG = MainActivity.class.getSimpleName();
public List<Upick> upicks;
private RecyclerView recyclerView;
private GridLayoutManager gridLayout;
private UpicksAdapter adapter;
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private String user_id;
private Button btnNew;
ListView UpicksListView;
ProgressBar progressBar;
String HttpURL = "http://***/upicks_todos.php";
private OnFragmentInteractionListener mListener;
public MisUpicksFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment MensajesFragment.
*/
// TODO: Rename and change types and number of parameters
public static MisUpicksFragment newInstance(String param1, String param2) {
MisUpicksFragment fragment = new MisUpicksFragment();
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);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_misupicks, container, false);
UpicksListView = (ListView) view.findViewById(R.id.UpicksListView);
progressBar = (ProgressBar) view.findViewById(R.id.ProgressBar1);
new ParseJSonDataClass(getActivity()).execute();
UpicksListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String item = UpicksListView.getItemAtPosition(position).toString();
Log.d("VALOR","VALOR "+item);
}
});
return view;
}
private class ParseJSonDataClass extends AsyncTask<Void, Void, Void> {
public Context context;
String FinalJSonResult;
List<Upick> upickFullFormList;
public ParseJSonDataClass(Context context) {
this.context = context;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Void doInBackground(Void... arg0) {
HttpServiceClass httpServiceClass = new HttpServiceClass(HttpURL);
try {
httpServiceClass.ExecutePostRequest();
if (httpServiceClass.getResponseCode() == 200) {
FinalJSonResult = httpServiceClass.getResponse();
if (FinalJSonResult != null) {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(FinalJSonResult);
JSONObject jsonObject;
Upick upick;
upickFullFormList = new ArrayList<Upick>();
for (int i = 0; i < jsonArray.length(); i++) {
upick = new Upick();
jsonObject = jsonArray.getJSONObject(i);
upick.Subject_Name = jsonObject.getString("id_servicio");
upick.Subject_Full_Form = jsonObject.getString("cliente_servicio");
upickFullFormList.add(upick);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
Toast.makeText(context, httpServiceClass.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void result)
{
progressBar.setVisibility(View.GONE);
UpicksListView.setVisibility(View.VISIBLE);
if (upickFullFormList != null) {
UpicksAdapter adapter = new UpicksAdapter(upickFullFormList, context);
UpicksListView.setAdapter(adapter);
}
}
}
private void logoutUser() {
session.setLogin(false);
// Launching the login activity
Intent intent = new Intent(getActivity(), LoginActivity.class);
startActivity(intent);
//finish();
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
Change this code to setters.
upick.Subject_Name = jsonObject.getString("id_servicio");
upick.Subject_Full_Form = jsonObject.getString("cliente_servicio");
eg:
upick.setSubjectname(jsonObject.getString("id_servicio"));
Then inside onclick you can take values using getters
String item = upicks.get(position).getSubjectname();
parent.getItemAtPosition(position) will return an Object (the model used in your adapter).To get some field from your Object don't call Object.toString(); it will return the object reference not the value that you're looking for. Use Object.yourField; instead.
The ArrayList.get() method is used to get the element of a specified
position within the list.
String str_ITEM= upicks.get(position).yourGETMETHOD();
in your callback listener you have adapter object just use that like below.
UpicksListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String item = parent.getSelectedItem().toString();
Log.d("VALOR","VALOR "+item);
}
});
Related
I basically want to display the data from firestore when the user selects an item from the second spinner and display it in a CardView inside RedcyclerView.
The code doesnt throw any errors but doesn't display the data either i.e nothing happens when an item is selected from the second spinner.
My Firestore Database schema is something like:
Tests > 7th (standard/grade) > Physics (subject) > QuestionNum > 1 > Document Auto-ID > qName,op1,op2,op3,op4,cop (fields).
This is QuestionListFragment.java where I want to display data
public class QuestionListFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
Spinner spin1,spin2;
String sub,std,TAG="QuestionListFragment";
private FirebaseFirestore db;
private CollectionReference ref;
private QuestionItemAdapter adapter;
RecyclerView recyclerView;
public QuestionListFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment QuestionListFragment.
*/
// TODO: Rename and change types and number of parameters
public static QuestionListFragment newInstance(String param1, String param2) {
QuestionListFragment fragment = new QuestionListFragment();
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);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_question_list, container, false);
db=FirebaseFirestore.getInstance();
spin1=(Spinner)view.findViewById(R.id.list_standard_spinner);
ArrayAdapter<String> arrayAdapter1 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_expandable_list_item_1, getResources().getStringArray(R.array.standard));
arrayAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin1.setAdapter(arrayAdapter1);
spin2= (Spinner) view.findViewById(R.id.list_subject_spinner);
ArrayAdapter<String> arrayAdapter2 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_expandable_list_item_1,getResources().getStringArray(R.array.subjects));
arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin2.setAdapter(arrayAdapter2);
spin2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
//sub=spin2.getSelectedItem().toString().trim();
setUpRecylerView();
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
recyclerView= view.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
return view;
}
public void setUpRecylerView(){
for (int i=1;i<=50;i++){
Log.d(TAG, "setUpRecylerView: In setuprecylerview");
std=spin1.getSelectedItem().toString().trim();
sub=spin2.getSelectedItem().toString().trim();
CollectionReference cref;
ref=db.collection("Tests").document(std).collection(sub).document("QuestionNum").collection(String.valueOf(i));
Query query = ref.orderBy("qName",Query.Direction.ASCENDING);
FirestoreRecyclerOptions<QuestionItem> options = new FirestoreRecyclerOptions.Builder<QuestionItem>()
.setQuery(query,QuestionItem.class)
.build();
adapter=new QuestionItemAdapter(options);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
adapter.startListening();
}
}
}
This is QuestionItem.java
public class QuestionItem {
private String qName;
private String op1;
private String op2;
private String op3;
private String op4;
private String cop;
public QuestionItem(){
// Empty Constructor
}
public QuestionItem(String qName, String op1, String op2, String op3, String op4, String cop){
this.qName=qName;
this.op1=op1;
this.op2=op2;
this.op3=op3;
this.op4=op4;
this.cop=cop;
}
public String getqName() {
return qName;
}
public String getOp1() {
return op1;
}
public String getOp2() {
return op2;
}
public String getOp3() {
return op3;
}
public String getOp4() {
return op4;
}
public String getCop() {
return cop;
}
}
This is the adapater class QuestionItemAdapter.java
public class QuestionItemAdapter extends FirestoreRecyclerAdapter<QuestionItem,
QuestionItemAdapter.NoteHolder> {
/**
* Create a new RecyclerView adapter that listens to a Firestore Query. See {#link
* FirestoreRecyclerOptions} for configuration options.
*
* #param options
*/
public QuestionItemAdapter(#NonNull FirestoreRecyclerOptions<QuestionItem> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull QuestionItemAdapter.NoteHolder holder, int position,
#NonNull QuestionItem model) {
holder.qname_textview.setText(model.getqName());
holder.op1_textview.setText(model.getOp1());
holder.op2_textview.setText(model.getOp2());
holder.op3_textview.setText(model.getOp3());
holder.op4_textview.setText(model.getOp4());
holder.cop_textview.setText(model.getCop());
}
#NonNull
#Override
public QuestionItemAdapter.NoteHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.question_item,parent,false);
return new NoteHolder(v);
}
class NoteHolder extends RecyclerView.ViewHolder{
TextView qname_textview,op1_textview,op2_textview,op3_textview,op4_textview,cop_textview;
public NoteHolder(#NonNull View itemView) {
super(itemView);
qname_textview=itemView.findViewById(R.id.qName_display);
op1_textview=itemView.findViewById(R.id.op1_display);
op2_textview=itemView.findViewById(R.id.op2_display);
op3_textview=itemView.findViewById(R.id.op3_display);
op4_textview=itemView.findViewById(R.id.op4_display);
cop_textview=itemView.findViewById(R.id.correct_op_display);
}
}
}
And I followed this tutorial for reference.
This is what I've got so far, but it only puts the value inside the database. I need to be able to see what's already inside it but I don't know how. Another good indicator would be to print a toast message with the number of entries on the database.
PS. bonus points if you can help me with crating a new activity expecting an object and retrieving a value when it is done to use it in the father activity. thank y'all.
public class DBHelper extends SQLiteOpenHelper{
private static final String TABLE = "Students";
private static final String DATABASE = "demo.db";
private static final int VERSION = 1;
private static final String C_ID = "id";
private static final String C_NAME = "name";
private static final String C_MAJOR = "major";
public DBHelper(Context context){
super(context, DATABASE, null, VERSION);
}
#Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String creationQuery = "CREATE TABLE " +
TABLE +
" (" +
C_ID +
" INTEGER PRIMARY KEY, " +
C_NAME +
" TEXT, " +
C_MAJOR +
" TEXT)";
sqLiteDatabase.execSQL(creationQuery);
}
#Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
String[] tables = {TABLE};
// prepared statements - check it out for your DB knowledge! yeah!
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS ?", tables);
onCreate(sqLiteDatabase);
// getWritableDatabase
}
public void saveRecord(String name, String major){
// retrieve a reference to the db that we're working with
SQLiteDatabase db = getWritableDatabase();
/*
String query = "INSERT INTO " + TABLE + "(" + C_NAME +", " + C_MAJOR + ") VALUES(?, ?)";
String[] params = {name, major};
db.execSQL(query, params);
*/
ContentValues cv = new ContentValues();
cv.put(C_NAME, name);
cv.put(C_MAJOR, major);
db.insert(TABLE, null, cv);
}
public int getRecord(String name){
SQLiteDatabase db = getWritableDatabase();
int result = -1;
String selection = "name = ?";
String[] params = {name};
Cursor c = db.query(TABLE, null, selection, params, null, null, null);
if(c.moveToFirst()){
result = c.getInt(0);
}
return result;
}
public int deleteRecord(String name) {
SQLiteDatabase db = getWritableDatabase();
String selection = "name = ?";
String[] params = {name};
return db.delete(TABLE, selection, params);
}
}
First this one on fragment
public class fragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
///
private ListView lista;
private MyAdapter_Amigos adapter_amigos;
private OnFragmentInteractionListener mListener;
public fragment() {
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static fragment newInstance(String param1, String param2) {
fragment fragment = new fragment();
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);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_fragment, container, false);
lista = (ListView) v.findViewById(R.id.list);
return v;
}
//Llena arreglo de amigos
public void Lista(ArrayList<Amigo> amigos){
adapter_amigos = new MyAdapter_Amigos(getActivity(), amigos);
lista.setAdapter(adapter_amigos);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
Then on main:
public class MainActivity extends AppCompatActivity implements fragment.OnFragmentInteractionListener, JSONCallback {
ArrayList<Amigo> amigos;
fragment frag;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frag = (fragment) getFragmentManager().findFragmentById(R.id.fragment);
}
#Override
public void callBack(JSONObject jo) {
try {
amigos = new ArrayList<Amigo>();
JSONArray arreglo = jo.getJSONArray("result");
for (int i = 0; i < arreglo.length(); i++){
JSONObject objeto = arreglo .getJSONObject(i);
Amigo amigo = new Amigo(objeto.getString("Nombre"),objeto.getString("Hobby"));
amigos.add(amigo);
}
}catch (Exception e){
}
//Log.d("xx",jo.toString());
frag.Lista(amigos);
}
public void LoadJson(View v){
JSONRequest reques = new JSONRequest(this);
reques.execute("https://raw.githubusercontent.com/my.json");
}
#Override
public void onFragmentInteraction(Uri uri) {
}
Then on Someone:
public class Amigo {
//ALT INSERT Constructor / ALT INSERT Setters and Getters
public String nombre;
public String hobby;
public Amigo(String nombre, String hobby) {
this.hobby = hobby;
this.nombre = nombre;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
Then on my adapter:
public class MyAdapter_Amigos extends BaseAdapter {
private Activity activity;
private ArrayList<Amigo> amigos;
public MyAdapter_Amigos(Activity activity, ArrayList<Amigo> amigos) {
this.activity = activity;
this.amigos = amigos;
}
#Override
public int getCount() {
return amigos.size();
}
#Override
public Object getItem(int position) {
return amigos.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
if(view == null){
view = activity.getLayoutInflater().inflate(R.layout.row,null);
}
TextView nombre = (TextView) view.findViewById(R.id.nombre);
TextView hobby = (TextView) view.findViewById(R.id.hobby);
nombre.setText((amigos.get(position).getNombre()));
hobby.setText(amigos.get(position).getHobby());
return view;
}
Then on JSONCallback:
import org.json.JSONObject;
public interface JSONCallback {
void callBack(JSONObject jo);
}
For last JSONRequest:
public class JSONRequest extends AsyncTask<String, Void, JSONObject> {
private JSONCallback activity;
public JSONRequest(JSONCallback activity){
this.activity = activity;
}
#Override
protected JSONObject doInBackground(String... params) {
JSONObject resultado = null;
try {
URL url = new URL(params[0]);
HttpURLConnection conexion = (HttpURLConnection) url.openConnection();
conexion.connect();
InputStream is = conexion.getInputStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String linea = "";
while ((linea = bf.readLine()) != null){
sb.append(linea);
}
resultado = new JSONObject(sb.toString());
}catch (Exception e){
}
return resultado;
}
#Override
protected void onPostExecute(JSONObject jsonObject) {
super.onPostExecute(jsonObject);
activity.callBack(jsonObject);
}
This is Fragment 2:
public class fragment extends Fragment implements View.OnClickListener, AdapterView.OnItemClickListener {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private ListView lista;
private TextView texto;
private EditText edit;
private Button boton;
private ArrayList<Amigo> friend;
private MyAdapter_Amigos adapter_amigos;
private OnFragmentInteractionListener mListener;
public fragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment fragment.
*/
// TODO: Rename and change types and number of parameters
public static fragment newInstance(String param1, String param2) {
fragment fragment = new fragment();
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);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_fragment, container, false);
lista = (ListView) v.findViewById(R.id.lista);
texto = (TextView) v.findViewById(R.id.textView3);
edit = (EditText) v.findViewById(R.id.editText2);
boton = (Button) v.findViewById(R.id.button3);
boton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mListener.BotonComunicacion(edit.getText().toString());
}
}
);
lista.setOnItemClickListener(this);
return v;
}
// TODO: Rename method, update argument and hook method into UI event
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public void LlenarLista(ArrayList<Amigo> amigos){
friend = amigos;
MyAdapter_Amigos adapter_amigos = new MyAdapter_Amigos(amigos ,getActivity());
lista.setAdapter(adapter_amigos);
}
public void cambiarATexto(String string){
texto.setText(string);
}
#Override
public void onClick(View v) {
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(), vizualizar_datos.class);
intent.putExtra("nombre", friend.get(position).getNombre());
intent.putExtra("hobby", friend.get(position).getHobby());
intent.putExtra("edad", friend.get(position).getEdad());
intent.putExtra("telefono", friend.get(position).getTelefono());
intent.putExtra("direccion", friend.get(position).getDireccion());
startActivity(intent);
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void BotonComunicacion(String string);
//onFragmentInteraction(Uri uri)
}
This is main 2:
public class MainActivity extends AppCompatActivity implements fragment.OnFragmentInteractionListener, JSONCallBack {
private TextView texto;
private EditText edit;
private ArrayList<Amigo> amigos;
private fragment frag;
private JSONRequest request;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
texto = (TextView) findViewById(R.id.texto1);
edit = (EditText) findViewById(R.id.editText);
amigos = new ArrayList<Amigo>();
frag = (fragment) getFragmentManager().findFragmentById(R.id.fragment);
}
#Override
public void CallBack(JSONObject jo) {
try{
JSONArray arreglo = jo.getJSONArray("result");
for(int i =0 ; i < arreglo.length(); i++){
JSONObject o = arreglo.getJSONObject(i);
Amigo amigo = new Amigo(o.getString("Nombre"),o.getString("Hobby"),o.getString("Edad"),o.getString("Telefono"),o.getString("Direccion"));
amigos.add(amigo);
}
}catch (Exception e){
}
frag.LlenarLista(amigos);
}
public void BotonLoad(View v){
request = new JSONRequest(this);
request.execute("https://raw.githubusercontent.com/example.json");
}
#Override
public void BotonComunicacion(String string) {
texto.setText(string);
}
public void MandarInformacion(View v){
frag.cambiarATexto(edit.getText().toString());
}
And the Viewrs:
public class vizualizar_datos extends AppCompatActivity {
private TextView nombre;
private TextView hobby;
private TextView edad;
private TextView direccion;
private TextView telefono;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vizualizar_datos);
nombre = (TextView) findViewById(R.id.nombre_vis);
hobby = (TextView) findViewById(R.id.hobby_vis);
edad = (TextView) findViewById(R.id.edad_vis);
direccion = (TextView) findViewById(R.id.direccion_vis);
telefono = (TextView) findViewById(R.id.telefono_vis);
Intent intent = getIntent();
nombre.setText(intent.getStringExtra("nombre"));
hobby.setText(intent.getStringExtra("hobby"));
edad.setText(intent.getStringExtra("edad"));
direccion.setText(intent.getStringExtra("telefono"));
telefono.setText(intent.getStringExtra("telefono"));
}
I am working on a RecyclerView which must be Draggable & swipeable. Everything works perfect.
The Data is getting Fetched in one class called ExerciseDataProvider & the RV code is another Fragment RecyclerListViewFragment.
The problem is that i can't notify Data changed from the FetchExercise on postExecute method. So the Data's are not getting populated in the RV.
Please Guide me in a Right Direction.
ACTIVITY
public class DraggableSwipeableExampleActivity extends AppCompatActivity {
private static final String FRAGMENT_TAG_DATA_PROVIDER = "data provider";
private static final String FRAGMENT_LIST_VIEW = "list view";
private static final String FRAGMENT_TAG_ITEM_PINNED_DIALOG = "item pinned dialog";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(new ExampleDataProviderFragment(), FRAGMENT_TAG_DATA_PROVIDER)
.commit();
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new RecyclerListViewFragment(), FRAGMENT_LIST_VIEW)
.commit();
}
}
public AbstractDataProvider getDataProvider() {
final Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DATA_PROVIDER);
return ((ExampleDataProviderFragment) fragment).getDataProvider();
}
DATA PROVIDER
public class ExerciseDataProvider extends AbstractDataProvider {
private List<ConcreteData> mData;
private ConcreteData mLastRemovedData;
private int mLastRemovedPosition = -1;
public ExerciseDataProvider() {
new FetchExercise().execute();
mData = new LinkedList<>();
}
class FetchExercise extends AsyncTask<Void,Void,Void> {
#Override
protected Void doInBackground(Void... params) {
final int viewType = 0;
final int swipeReaction = RecyclerViewSwipeManager.REACTION_CAN_SWIPE_UP | RecyclerViewSwipeManager.REACTION_CAN_SWIPE_DOWN;
String url = "https://gist.githubusercontent.com/fake/cb9aa5494e7ee36ac3ca/raw/a4abfd19368063/exercise.JSON";
Log.d("Path", url);
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
String jsonData = response.body().string();
try {
JSONArray jsonArray = new JSONArray(jsonData);
for (int i = 0; i < jsonArray.length(); i++) {
final long id = i;
JSONObject jsonObject = jsonArray.getJSONObject(i);
String exercise_name = jsonObject.getString("name");
int exercise_duration = jsonObject.getInt("duration");
mData.add(new ConcreteData(id, viewType, exercise_name, exercise_duration, swipeReaction));
Log.d("exercise_name", exercise_name);
}
} catch (JSONException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
}
#Override
public int getCount() {
return mData.size();
}
#Override
public Data getItem(int index) {
if (index < 0 || index >= getCount()) {
throw new IndexOutOfBoundsException("index = " + index);
}
return mData.get(index);
}
#Override
public int undoLastRemoval() {
if (mLastRemovedData != null) {
int insertedPosition;
if (mLastRemovedPosition >= 0 && mLastRemovedPosition < mData.size()) {
insertedPosition = mLastRemovedPosition;
} else {
insertedPosition = mData.size();
}
mData.add(insertedPosition, mLastRemovedData);
mLastRemovedData = null;
mLastRemovedPosition = -1;
return insertedPosition;
} else {
return -1;
}
}
#Override
public void moveItem(int fromPosition, int toPosition) {
if (fromPosition == toPosition) {
return;
}
final ConcreteData item = mData.remove(fromPosition);
mData.add(toPosition, item);
mLastRemovedPosition = -1;
}
#Override
public void removeItem(int position) {
//noinspection UnnecessaryLocalVariable
final ConcreteData removedItem = mData.remove(position);
mLastRemovedData = removedItem;
mLastRemovedPosition = position;
}
public static final class ConcreteData extends Data {
private final long mId;
private final String mText;
private final int mViewType;
private final int mDuration;
private boolean mPinned;
ConcreteData(long id, int viewType, String text, int duration, int swipeReaction) {
mId = id;
mViewType = viewType;
mText = text;
mDuration = duration;
}
#Override
public int getViewType() {
return mViewType;
}
#Override
public int getDuration() {
return mDuration;
}
#Override
public long getId() {
return mId;
}
#Override
public String toString() {
return mText;
}
#Override
public String getText() {
return mText;
}
#Override
public boolean isPinned() {
return mPinned;
}
#Override
public void setPinned(boolean pinned) {
mPinned = pinned;
}
}
}
RecyclerListViewFragment
public class RecyclerListViewFragment extends Fragment {
private RecyclerView mRecyclerView;
private RecyclerView.LayoutManager mLayoutManager;
private RecyclerView.Adapter mAdapter;
private RecyclerView.Adapter mWrappedAdapter;
private RecyclerViewDragDropManager mRecyclerViewDragDropManager;
private RecyclerViewSwipeManager mRecyclerViewSwipeManager;
private RecyclerViewTouchActionGuardManager mRecyclerViewTouchActionGuardManager;
public RecyclerListViewFragment() {
super();
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_recycler_list_view, container, false);
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//noinspection ConstantConditions
mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
mLayoutManager = new LinearLayoutManager(getContext());
// touch guard manager (this class is required to suppress scrolling while swipe-dismiss animation is running)
mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
mRecyclerViewTouchActionGuardManager.setEnabled(true);
// drag & drop manager
mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
(NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3));
// swipe manager
mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();
//adapter
final MyDraggableSwipeableItemAdapter myItemAdapter = new MyDraggableSwipeableItemAdapter(getDataProvider());
myItemAdapter.setEventListener(new MyDraggableSwipeableItemAdapter.EventListener() {
#Override
public void onItemRemoved(int position) {
((DraggableSwipeableExampleActivity) getActivity()).onItemRemoved(position);
}
#Override
public void onItemViewClicked(View v, boolean pinned) {
onItemViewClick(v, pinned);
}
});
mAdapter = myItemAdapter;
mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging
mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mWrappedAdapter); // wrap for swiping
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
animator.setSupportsChangeAnimations(false);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter
mRecyclerView.setItemAnimator(animator);
// additional decorations
//noinspection StatementWithEmptyBody
if (supportsViewElevation()) {
// Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
} else {
mRecyclerView.addItemDecoration(new ItemShadowDecorator((NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
}
mRecyclerView.addItemDecoration(new SimpleListDividerDecorator(ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true));
mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);
mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);
}
#Override
public void onPause() {
mRecyclerViewDragDropManager.cancelDrag();
super.onPause();
}
#Override
public void onDestroyView() {
if (mRecyclerViewDragDropManager != null) {
mRecyclerViewDragDropManager.release();
mRecyclerViewDragDropManager = null;
}
if (mRecyclerViewSwipeManager != null) {
mRecyclerViewSwipeManager.release();
mRecyclerViewSwipeManager = null;
}
if (mRecyclerViewTouchActionGuardManager != null) {
mRecyclerViewTouchActionGuardManager.release();
mRecyclerViewTouchActionGuardManager = null;
}
if (mRecyclerView != null) {
mRecyclerView.setItemAnimator(null);
mRecyclerView.setAdapter(null);
mRecyclerView = null;
}
if (mWrappedAdapter != null) {
WrapperAdapterUtils.releaseAll(mWrappedAdapter);
mWrappedAdapter = null;
}
mAdapter = null;
mLayoutManager = null;
super.onDestroyView();
}
private void onItemViewClick(View v, boolean pinned) {
int position = mRecyclerView.getChildAdapterPosition(v);
if (position != RecyclerView.NO_POSITION) {
((DraggableSwipeableExampleActivity) getActivity()).onItemClicked(position);
}
}
public AbstractDataProvider getDataProvider() {
return ((DraggableSwipeableExampleActivity) getActivity()).getDataProvider();
}
public void notifyItemChanged(int position) {
mAdapter.notifyItemChanged(position);
}
public void notifyItemInserted(int position) {
mAdapter.notifyItemInserted(position);
mRecyclerView.scrollToPosition(position);
}
}
To update recyclerView from onPostExecute in a data provider class, your onPostExecute should have access to context where your recyclerView is defined.
Since your FetchExercise async task is defined inside ExerciseDataProvider class, try passing activity context to ExerciseDataProvider's constructor and then pass it on to FetchExercise async task as described here: getting context in AsyncTask
public class MyCustomTask extends AsyncTask<Void, Void, Long> {
private Context mContext;
public MyCustomTask (Context context){
mContext = context;
}
protected void onPostExecute(Long result) {
//use mContext to update recycler view
}
}
}
Use the context to update the recyclerView.
UPDATE
Step 1
Define an interface that will notify your activity of data set change inside a class that initialises your data provider class and pass activity context to constructor of data provider class.
public class ExampleDataProviderFragment extends Fragment {
private AbstractDataProvider mDataProvider;
//Define an interface that will notify your activity of data set change
public interface EventListener {
void onNotifyDataSetChanged();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
//Pass activity context to ExerciseDataProvider
mDataProvider = new ExerciseDataProvider(getActivity());
}
public AbstractDataProvider getDataProvider() {
return mDataProvider;
}
}
Step 2
Add context parameter to ExerciseDataProvider's constructor and use it to notify activity that implements your interface to notify dataset change.
public class ExerciseDataProvider extends AbstractDataProvider {
private List<ConcreteData> mData;
private ConcreteData mLastRemovedData;
private int mLastRemovedPosition = -1;
//Add context parameter to constructor
public ExerciseDataProvider(Context context) {
//Pass context to async task
new FetchExercise(context).execute();
mData = new LinkedList<>();
}
class FetchExercise extends AsyncTask<Void,Void,Integer> {
Context mContext;
public FetchExercise(Context context) {
mContext = context;
}
#Override
protected Integer doInBackground(Void... params) {
...
return 1;
}
#Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
//Typecast context to interface defined above
//and notify dataset changes by calling its method
ExampleDataProviderFragment.EventListener eventListener = (ExampleDataProviderFragment.EventListener)mContext;
eventListener.onNotifyDataSetChanged();
}
}
}
Step 3
Implement above defined interface in your activity class and notify recyclerview adapter inside it
public class DraggableSwipeableExampleActivity extends AppCompatActivity
implements ExampleDataProviderFragment.EventListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
...
}
//implement interface method and notify recyclerview of changes
#Override
public void onNotifyDataSetChanged() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_LIST_VIEW);
// you might need to change visibility of `mWrappedAdapter` in the fragment that defines it or create a getter for it so that you can access it here
((RecyclerListViewFragment) fragment).mWrappedAdapter.notifyDataSetChanged();
}
...
}
I think #random is correct you should be notifying your Recycle view on post execute.
#Override
protected void onPostExecute(Void aVoid) {
mRecyclerViewAdapter.notifyDataSetChanged();
super.onPostExecute(aVoid);
}
or if you have done something in your async task to add/delete something in the data set you would do:
#Override
protected void onPostExecute(Void aVoid) {
mRecyclerViewAdapter.notifyItemRemoved(itemposition); // or item added
mRecyclerViewAdapter.notifyDataSetChanged();
super.onPostExecute(aVoid);
}
Hope it helps !
I have view pager in my app. inside a viewpager there are two fragments [1] and [2] both with list view inside [A] and [B]. when I scroll listview [A] and switch fragment [2] I want listview [B] to be scrolled with the same amount automatically. please help
here is my snippet
public class CurrencyViewPager extends BaseFragment {
private ListView mcurrencyListview;
private GeoCurrencyService mCurrency = GeoCurrencyService.getInstance();
ButtonPressListener buttonListener;
private CurrencyAdapter mCurrencyAdapter;
private String bankName;
private boolean checkFlag;
private ProgressBar mCurrencyProgress;
private TextView mCurrencyLoading;
private List<Currency> mList;
private String recCode;
private static int Firstposition;
private final CurrencyScrollListener listener;
private final int mListViewIndex;
// constructor
public CurrencyViewPager(List<Currency> myList, String name, boolean flag,String code, CurrencyScrollListener listener, int listViewIndex) {
super();
this.mList = myList;
this.bankName = name;
this.checkFlag = flag;
this.recCode = code;
this.listener = listener;
this.mListViewIndex = listViewIndex;
}
// interface
public interface ButtonPressListener {
public void onListItemPressed(Currency object, String name,String code);
}
// attach on listener
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
buttonListener = (ButtonPressListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement onButtonPressed");
}
}
// creating the main View.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
Log.i("TAG","onCreateView");
View view = inflater.inflate(R.layout.listbuy, container, false);
mcurrencyListview = (ListView) view.findViewById(R.id.BuyList);
mCurrencyAdapter = new CurrencyAdapter(getActivity(),
R.layout.currency_row, mList, checkFlag, getLanguage());
mcurrencyListview.setAdapter(mCurrencyAdapter);
mcurrencyListview.setSelection(Firstposition);
// calling method getCurrency which take bank code as a parameter
/*getCurrency(code,null);*/
// reference to the list view of the corresponding layout
mcurrencyListview.setOnItemClickListener(new OnItemClickListener() {
// onClick on the List item
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// getting Currency object according to the position
Currency currencyObject = mCurrencyAdapter.getItem(position);
// sending the object to the mainActivity
buttonListener.onListItemPressed(currencyObject, bankName,recCode);
}
});
return view;
}
// method getCurrency which takes bank code as a parameter and
// sets the adapter to the list on onPostExecute.
}
and fragment adapter for viewpager
public class ViewPagerAdapter extends FragmentStatePagerAdapter implements
CurrencyScrollListener {
private String nBankName;
private List<Currency> list;
private String mycode;
private CurrencyViewPager[] mFragments = new CurrencyViewPager[2];
private int mCurrentScrollPosition;
#Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return super.getItemPosition(object);
}
public CurrencyViewPager getFCurrencyFragment(int index) {
CurrencyViewPager pager = mFragments[index];
if (pager == null) {
if (index == 0) {
pager = new CurrencyViewPager(list, nBankName, true, mycode,
this, 0);
} else {
pager = new CurrencyViewPager(list, nBankName, false, mycode,
this, 1);
}
mFragments[index] = pager;
}
return pager;
}
public ViewPagerAdapter(FragmentManager fm, List<Currency> currencyList,
String name, String code) {
super(fm);
this.list = currencyList;
this.nBankName = name;
this.mycode = code;
}
#Override
public Fragment getItem(int item) {
Log.i("TAG","getItem");
return getFCurrencyFragment(item);
}
#Override
public int getCount() {
return 2;
}
}
I have a SherlockFragmentActivity class that collects values from a server and loads it in to my database. This SherlockFragmentActivity as 3 Fragment called the Book, Video and Audios. Each of them are meant to show values that were downloaded into the db. By challenge now is when I open my UI i dont get to see the values on the fragments not until I start clicking each fragment before the values get populated into the list in the fragment. And I even notice a continuous addition of this values. My fragment class is pasted below.
public class BooksFragment extends SherlockListFragment{
TextView textview = null;
String CategoryID = null;
ArrayList<HashMap<String,String>> listBooks = null;
IDatabaseHelper databaseHelper = null;
Activity activity = null;
Context context = null;
ListAdapter adapter = null;
public BooksFragment(){
super();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.books, container, false);
// do your view initialization heres
textview = (TextView)view.findViewById(R.id.textView1);
return view;
}
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
listBooks = new ArrayList<HashMap<String,String>>();
}
#Override
public void onStart() {
super.onStart();
Bundle bundle =this.getArguments();
if(bundle != null){
CategoryID = bundle.getString("CategoryID");
}
this.initializeComponents();
this.populateListView();
}
#Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
activity = getActivity();
context = activity.getBaseContext();
databaseHelper= new DatabaseHelper(context);
}
//Now we are going to initialize components of the fragment
private void initializeComponents(){
ListView listview = getListView();
listview.setOnItemClickListener(listener);
}
//list item click listener
private OnItemClickListener listener = new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
}
};
//This method would be used to collect content from the database and populate the listview item
private void populateListView(){
MedicalBookModel[] booksmodel = this.databaseHelper.ReturnBooks(CategoryID);
if(booksmodel != null){
for(MedicalBookModel book : booksmodel){
HashMap<String,String> bookMap = new HashMap<String,String>();
bookMap.put(MedicalBookModel.MedicalBookModel_ID, book.getID());
bookMap.put(MedicalBookModel.MedicalBookModel_Name,book.getName());
Log.i("values",book.getName());
listBooks.add(bookMap);
}
}
adapter = new SimpleAdapter(context, listBooks,R.layout.list_book,new String[]{ "ID","Name"}, new int[]{ R.id.bookId, R.id.bookName});
setListAdapter(adapter);
}
}
For that you have several solutions :
1- Using the Application instance singleton which is global
2- Creating your own global class to manage your data
3- Use a service bound to the activity (or not) and call backs (maybe intent and broadcast receivers)
4- Pass your object as parceable in argument when adding the fragment
Note that sometimes you will need to invalidate views to force datas to refresh
EXEMPLE OF PARCEABLE OBJECT
public class ImageObject implements Parcelable {
/**
* ATTRIBUTES
*/
protected String _idPicture;
protected String _idAlbum;
protected String _name;
protected String _fileName;
protected String _imageUrl;
protected String _hierarchy;
public ImageObject(String _idPicture, String _idAlbum, String _name, String _fileName, String _imageUrl, String _hierarchy) {
super();
this._idPicture = _idPicture;
this._idAlbum = _idAlbum;
this._name = _name;
this._fileName = _fileName;
this._imageUrl = _imageUrl;
this._hierarchy = _hierarchy;
}
public ImageObject(Parcel in) {
String[] data = new String[6];
in.readStringArray(data);
this._idPicture = data[0];
this._idAlbum = data[1];
this._name = data[2];
this._fileName = data[3];
this._imageUrl = data[4];
this._hierarchy = data[5];
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public ImageObject createFromParcel(Parcel in) {
return new ImageObject(in);
}
public ImageObject[] newArray(int size) {
return new ImageObject[size];
}
};
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringArray(new String[] { this._idPicture, this._idAlbum, this._name, this._fileName, this._imageUrl, this._hierarchy });
}
}