Created
April 16, 2012 09:20
-
-
Save ytRino/2397221 to your computer and use it in GitHub Desktop.
複数ListView in ListActivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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