Mon application n’exécute pas toujours le code en fonction du terminal (oui oui)
Par exemple sur mon Galaxy Scl l'application fonctionnement parfaitement bien
Sur le Galaxy Y la listView n’apparaît pas.
Sur le terminal la listView n’apparaît pas non plus
Voici mon code
public class TestsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videos);
ListView listVideo = null;
Context context = this;
listVideo = (ListView)findViewById(R.video.listViewVideo);
try{
HttpClient client = new DefaultHttpClient();
HttpUriRequest request = new HttpGet("https://gdata.youtube.com/feeds/api/videos?author=trbourgois&v=2&alt=jsonc");
HttpResponse response = client.execute(request);
String jsonString = (response.getEntity() == null) ? null : EntityUtils.toString(response.getEntity());
JSONObject json = new JSONObject(jsonString);
JSONArray jsonArray = json.getJSONObject("data").getJSONArray("items");
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map ;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
map = new HashMap<String, Object>();
map.put("titre", jsonObject.getString("title"));
map.put("id", jsonObject.getString("id"));
map.put("uploaded", jsonObject.getString("uploaded"));
map.put("url", "http://www.youtube.com/v/"+jsonObject.getString("id")+"?version=3");
listItem.add(map);
}
SimpleAdapter adapter = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.affichageitem,
new String[] {"img", "titre", "uploaded"}, new int[] {R.video.miniaturevideo, R.video.titre, R.video.date}); listVideo.setAdapter(adapter);
}catch (Exception e) {
e.printStackTrace();
}
listVideo.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View view, int position,long id) {
}
});
}
}
Mon XML :
videos.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+video/listViewVideo" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout></code>
affichageitems.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:id="@+video/miniaturevideo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:padding="10dp" android:contentDescription="bouh" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:paddingLeft="10dp" android:layout_weight="1" > <TextView android:id="@+video/titre" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textSize="16dp" android:textStyle="bold" /> <TextView android:id="@+video/date" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> </LinearLayout>
Merci de votre aide







Retour en haut







