public class RisorseActivity extends DashboardActivity implements Observer { private Docente docente; private String get_response; private String response; //private HttpsClient client; private ListView list; private RelativeLayout progressLayout; private ProgressBar progressBar; private TextView txtMateriale; private ArrayList<risorsa> risorseList; private RisorseAdapter risAdapter; private RisorseList risList; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_risorse); setTitleFromActivityLabel(R.id.title_text); list = (ListView) findViewById(R.id.ListRisorse); list.setClickable(true); Intent intent = getIntent(); // vengono recuperati i parametri dalla activity chiamante docente = (Docente) intent.getSerializableExtra(getPackageName() + ".Docente"); //cartella = (Insegnamento) intent.getSerializableExtra(pkg + ".Insegnamento"); get_response = intent.getExtras().getString("get_response"); response = intent.getExtras().getString("response"); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView int position, long index) { if (risorseList.get(position).getType().equalsIgnoreCase("Folder")) { Intent intRisorse = new Intent(getApplicationContext(), RisorseActivity.class); intRisorse.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intRisorse.putExtra(getPackageName() + ".Docente", docente); intRisorse.putExtra("get_response", risorseList.get(position).getURL()); startActivity(intRisorse); } else if (risorseList.get(position).getType().equalsIgnoreCase("File")) { //--------------- DOWNLOAD DEL FILE------------------- } } }); startRisorseService(); } // Aggiorna la View della Activity popolando la lista dei docenti trovati private void updateView() { this.risAdapter = new RisorseAdapter(this, this.risorseList); if (this.risAdapter != null) { this.list.setAdapter(this.risAdapter); } else { Toast.makeText(this, "Errore caricamento lista materiale", Toast.LENGTH_LONG).show(); } } private void startRisorseService() { // risList conterrà il nostro modello dei dati (l'array di oggetti // Ricevimento) risList = RisorseList.getInstance(); if (risList.countObservers() == 0) risList.addObserver(this); // aggiungiamo la nostra "View" come // osservatore del modello dati loginState = ((LoginState) getApplicationContext()); Handler handler = new RisorseHandler(); //IT IS THE TASK THATH RETRIEVE THE DATA RisorseService task = null; if (response != null){ task = new RisorseService(handler, loginState, response); }else task = new RisorseService(handler, loginState); if (task != null) task.execute(get_response); } public void update(Observable observable, Object arg1) { if(observable instanceof RisorseList){ // in quanto potremmo avere piu modelli dati // verifichiamo su quale modello è avvenuto un cambiamento dei dati // prima di effettuare il cast this.risorseList = ((RisorseList) observable).getData(); } updateView(); risList.deleteObserver(this); } public void onClickRefresh(View v) { startRisorseService(); } @Override protected void onResume(){ super.onResume(); // IF I UNCOMMENT THESE LINES IT WORK BUT RETRIEVE DATA FROM INTERNET AGAIN!!! /*if (risAdapter == null) startRisorseService(); else{ risAdapter.notifyDataSetChanged(); }*/ if (risAdapter != null) updateView(); } }
StartActivity(Response);
Response=intent.getExtras().getString("response");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)