行がカスタムレイアウトのリストを含むActivity
を作成したいとします。 だから私は私のリストの各行が持つべきレイアウトを定義list_entry_layout.xml
ファイル(私の例では、各行は、タイトルと要約を持っている必要があります)を作成しました:私の問題は、私にはわからないということですカスタマイズされた行レイアウトを使用したListView - Android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/list_entry_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp" >
</TextView>
<TextView
android:id="@+id/list_entry_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" >
</TextView>
</LinearLayout>
をListActivity
クラスの各行にデータを追加する方法。私は、各行のタイトルを追加することができるよ次のコードスニペットで :
public class MyActivity extends ListActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list_activity);
ListView listView = (ListView) findViewById(android.R.id.list);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
ArrayAdapter<String> titleAdapter = new ArrayAdapter<String>(this, R.layout.list_entry_layout, R.id.list_entry_title, values);
// Assign adapter to ListView
listView.setAdapter(titleAdapter);
}
}
も私が何をすべきか要約を追加するための?
私はこのコードを追加した場合、私は要約を可視化していて、ではないだろうタイトル:
String[] values = new String[] { "Android_summary", "iPhone_summary", "WindowsMobile_summary", "Blackberry_summary", "WebOS_summary", "Ubuntu_summary", "Windows7_summary", "Max OS X_summary", "Linux_summary", "OS/2_summary" };
ArrayAdapter<String> summaryAdapter = new ArrayAdapter<String>(this, R.layout.list_entry_layout, R.id.list_entry_summary, values);
// Assign adapter to ListView
listView.setAdapter(summaryAdapter);
次は私が取得したいのですが、結果である:
唯一の解決策はありますか? – Matteo
'ArrayAdapter'の' getView() 'メソッドをオーバーライドして、リストを埋めなければなりません。 – nhaarman
私は2つの可能性がありますか?どちらがあなたの意見に優れているか、メソッドをオーバーライドしているか、自分の配列アダプタを記述していますか? – Matteo