Skip to content

Instantly share code, notes, and snippets.

@ytRino
Created April 16, 2012 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytRino/2397221 to your computer and use it in GitHub Desktop.
Save ytRino/2397221 to your computer and use it in GitHub Desktop.
複数ListView in ListActivity
package net.nessness.android.sample.listview;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class ListViewSampleActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
String[] from = new String[]{"test"};
int[] to = new int[]{android.R.id.text1};
for(int i = 0; i < 10; i++){
HashMap<String, String> m = new HashMap<String, String>();
m.put(from[0], "data " + i);
data.add(m);
}
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_1, from, to);
// @id/android:list (android.R.id.list) の ListViewにアダプターをセット
setListAdapter(adapter);
// R.id.mylist のListViewにアダプターをセット
((ListView)findViewById(R.id.mylist)).setAdapter(adapter);
}
}
<?xml version="1.0" encoding="utf-8"?>
<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="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<ListView
android:id="@+id/mylist"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment