にListViewコントロールに動的に複利の項目を追加し、文字列タイプの項目が動的に追加されますListViewを作成するアイテムが複合化されたときに機能しなくなりました(私はIndexOutOfBoundsExceptionを取得します)。ArrayAdapterによって移入した後、この好適な例ではJavaの
public class VideoItem {
private String title;
private String description;
private String thumbnailURL;
private String id;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getThumbnailURL() {
return thumbnailURL;
}
public void setThumbnailURL(String thumbnailURL) {
this.thumbnailURL = thumbnailURL;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
とそのxmlファイルは次のとおりです:リストビューに追加する非簡単な項目の例がある
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="?android:attr/activatedBackgroundIndicator">
<ImageView
android:id="@+id/video_thumbnail"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"/>
<TextView
android:id="@+id/video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/video_thumbnail"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:textStyle="bold" />
<TextView
android:id="@+id/video_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/video_thumbnail"
android:layout_below="@+id/video_title"
android:textSize="15sp" />
</RelativeLayout>
まあ、ListViewコントロールは、によって作成された後、プログラムVideoItemを追加するコードArrayAdapterは次のようになります。
VideoItem objVideoItem = new VideoItem();
objVideoItem.setTitle("A Title");
objVideoItem.setDescription("This is a Description");
objVideoItem.setThumbnailURL("/storage/emulated/0/Cores.png");
searchResultsGloVideoItemList.add(objVideoItem);
youtubeGloVideoItemAdapter.notifyDataSetChanged();
正しく行う方法は?何か案が?ありがとう
完全な例外スタックトレースをお願いします。 – donfuxx
ご協力いただきありがとうございます。リストビューに複合オブジェクトを追加するコードがわからないため、スタックログを提供しませんでした。私は単純でないオブジェクトで同様のケースを見つけることができなかったので、コードの一部が正しいかどうかわからないので、おそらくそれは修正する必要があり、以前のスタックトレースは無関係です。 –