我想先說我對android開發很陌生。列表中每個項目的左右兩側都有文字? (Android)
我的問題是我如何改變我的下面的例子,以允許在每個列表項的左側和右側的文本。
我的目標是讓每個列表項目在左邊都有一個項目說明,右邊是該說明的一個數值。
所有我到現在是一個列表,顯示我想要在每個項目的左側顯示的值。
主要的Java活動(NewtestActivity.java):
public class NewtestActivity extends Activity {
String[] exampleList = {
"Item 1",
"Item 2",
"Item 3",
"Test 4",
"Item 5",
"Test 6",
"Item 7",
"Test 8"
//etc etc
};
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get an instance of your listview in code
ListView listview = (ListView) findViewById(R.id.list);
// Set the listview's adapter
listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, exampleList));
}
}
的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="280dp"
android:layout_height="fill_parent"
>
<ImageView
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_marginLeft="5dp"
android:text="@string/app_name"
/>
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="200dp"
/>
</LinearLayout>
感謝您的幫助(:
您應該必須使用自定義ListView。以下是一些有用的鏈接: http://appfulcrum.com/?p=311 http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ –