有關讀取的數組項,並顯示到一個ListView:
ArrayList titles = new ArrayList();
ArrayList descs= new ArrayList();
ArrayList links= new ArrayList();
for (int i = 0; i < titlesObj.length(); i++) {
String title = titlesObj.getString(i);
titles.add(title);
System.out.println("Titles: " + title);
}
for (int i = 0; i < descsObj.length(); i++) {
String desc = descsObj.getString(i);
descs.add(title);
System.out.println("Desc: " + desc);
}
for (int i = 0; i < linksObj.length(); i++) {
String link = linksObj.getString(i);
links.add(title);
System.out.println("Link: " + link);
}
接下來你做此ArrayList到ListView來源是這樣的:
// Get a handle to the list views
//get your instance of the listview for titles
ListView lvTitle = (ListView) findViewById(R.id.ListView01);
lv.setAdapter(new ArrayAdapter<string>((Your activity class).this,
android.R.layout.simple_list_item_1, titles));
//get your instance of the listview for descriptions
ListView lvDesc = (ListView) findViewById(R.id.ListView02);
lv.setAdapter(new ArrayAdapter<string>((Your activity class).this,
android.R.layout.simple_list_item_1, descs));
//get your instance of the listview for links
ListView lvLinks = (ListView) findViewById(R.id.ListView03);
lv.setAdapter(new ArrayAdapter<string>((Your activity class).this,
android.R.layout.simple_list_item_1, links));
編輯:
好吧,無論我說應該已經解決了你的問題。在真主裏。但是,我可以看到你正在使用相同的活動來溝通一個rem ote服務器來獲取數據。我建議,如果您爲此單獨創建一個類,最好返回json文本data
。然後,您可以從您的活動中調用此類來獲取數據並設置活動中的列表視圖。這將避免不必要的滯後和強制關閉您的應用程序。
如果這解決了您的問題,請將其標記爲幫助他人的答案。
UPDATE:
你需要實現一個自定義的適配器that.You需要定義一個listitem.xml
使用佈局按照您的requirement.Then它膨脹到列表視圖。按照tutorial。
樣品行:
list_row.xml
<!-- ListRow Left sied Thumbnail product image -->
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="@drawable/image_bg"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/someImage"/>
</LinearLayout>
<!-- Your title-->
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="Big Title"
android:textColor="#040404"
android:typeface="sans"
android:textSize="15dip"
android:textStyle="bold"/>
<!-- Your subtitle -->
<TextView
android:id="@+id/subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="Smaller sub title" />
<!-- Rightend info -->
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/title"
android:gravity="right"
android:text="info"
android:layout_marginRight="5dip"
android:textSize="10dip"
android:textColor="#10bcc9"
android:textStyle="bold"/>
<!-- Rightend Arrow -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
這將使你的列表行的樣子:
注:我不鼓勵音樂personally.This只是一個example.Please用它來做一個更好的目的:微笑:
爲什麼要使用三種不同的listview?我想在一個listview中顯示結果,其單行由標題,desc和URL組成。 – Anupam 2013-02-28 09:26:52
好吧,你應該提到你需要達到什麼目標。等幾分鐘inshallah – Nezam 2013-02-28 09:27:25
Ameen ... !!!!!!!! – Anupam 2013-02-28 09:31:32