Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package it.proprionoi.volleytest;
- import android.app.Activity;
- import android.util.Log;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ListAdapter;
- import android.widget.TextView;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- public class elencoUtentiAdapter extends BaseAdapter implements ListAdapter
- {
- private JSONArray ar;
- private Activity activity;
- public elencoUtentiAdapter(Activity a, JSONArray ar)
- {
- this.activity = a;
- this.ar = ar;
- }
- @Override
- public int getCount()
- {
- int retValue = 0;
- if(ar != null)
- retValue = ar.length();
- return retValue;
- }
- @Override
- public JSONObject getItem(int i)
- {
- JSONObject retObject = null;
- if(ar!=null)
- {
- try
- {
- retObject = ar.getJSONObject(i);
- }
- catch (JSONException ex)
- {
- Log.e("elencoUtentiAdapeter",ex.getMessage());
- }
- }
- return retObject;
- }
- @Override
- public long getItemId(int i)
- {
- long retID = 0;
- if(ar!=null)
- {
- try
- {
- JSONObject o = getItem(i);
- retID = o.getInt("idutente");
- }
- catch (JSONException ex)
- {
- Log.e("elencoUtentiAdapeter",ex.getMessage());
- }
- }
- return retID;
- }
- @Override
- public View getView(int i, View view, ViewGroup viewGroup)
- {
- if(view==null)
- {
- view = activity.getLayoutInflater().inflate(R.layout.cella_layout,null);
- }
- // Recupero il dato da mappare dall'arry JSON
- JSONObject o = getItem(i);
- // Ottengo i riferimenti JAVA agli oggetti del layout della cella
- TextView nomeTextView = (TextView) view.findViewById(R.id.nomeTextView);
- TextView cognomeTextView = (TextView) view.findViewById(R.id.cognomeTextView);
- TextView emailTextView = (TextView) view.findViewById(R.id.emailTextView);
- // Binding
- try
- {
- nomeTextView.setText(o.getString("nome"));
- cognomeTextView.setText(o.getString("cognome"));
- emailTextView.setText(o.getString("email"));
- }
- catch (JSONException ex)
- {
- Log.e("elencoUtentiAdapter",ex.getMessage());
- }
- // Rendiamo la vista della cella appena creata/aggiornata al chiamante
- // Il chiamante è sempre la ListView
- return view;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement