1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.TextView;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestHandle;
import cz.msebera.android.httpclient.Header;
public class MuseeActivity extends AppCompatActivity {
private static final String BASE_URL = "https://opendata.paris.fr/api/records/1.0/search/?dataset=liste-musees-de-france-a-paris&rows=50&pretty_print=true";
public String dateInString;
public String dateFormatString;
TextView textList;
ListView listView;
MuseeJSON responseObj;
CustomAdapter adapter1;
Gson gson;
AsyncHttpClient client;
private MuseeAdapter adapter;
private CustomAdapter listAdapter;
private GoogleApiClient client2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.each_list_item);
listView = (ListView) findViewById(R.id.listeMusee1);
this.setListAdapter(adapter1);
//On instancie notre client qui récupère la connexion au client http
client = new AsyncHttpClient();
RequestHandle requestHandle = client.get(MuseeActivity.this, BASE_URL, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
String responsestr = new String(responseBody);
gson = new Gson();
responseObj = gson.fromJson(responsestr, MuseeJSON.class);
adapter1 = new CustomAdapter(MuseeActivity.this, responseObj.getRecords());
//textList.setAdapter(adapter1);
listView.setAdapter(adapter1);
textList.setText((CharSequence) adapter1); //test ici
}
/**ArrayList<CustomAdapter> objects = new ArrayList<CustomAdapter>();
CustomAdapter customAdapter = new CustomAdapter(this, objects); //erreur ici
listView.setAdapter(customAdapter); //setAdapter non reconnu, ça doit être une grosse erreur de débutant
CustomAdapter.getView();**/
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
}
});
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
public void setListAdapter(CustomAdapter listAdapter) {
this.listAdapter = listAdapter;
}
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Musee Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client2.connect();
AppIndex.AppIndexApi.start(client2, getIndexApiAction());
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client2, getIndexApiAction());
client2.disconnect();
}
} |
Partager