Android
ListView안에 ScrollView 삽입
venustas
2011. 11. 16. 10:29
main.xml
<?xml version="1.0" encoding="utf-8"?>
list.xml
java
<?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">
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"/>
</LinearLayout>
list.xml
<?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">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/writeDate"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
<TextView android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView)findViewById(R.id.list);
SimpleAdapter adapter = new SimpleAdapter(this, makeList(arrayList), R.layout.list
, new String[]{ "writeDate", "title" }
, new int[]{ R.id.writeDate, R.id.title });
listView.setAdapter(adapter);
// SimpleAdapter 객체 생성 후 추가된 데이터가 있을 경우 아래 코드 실행
// adapter.notifyDataSetChanged();
}
private ArrayList<HashMap<String, String>> makeList(ArrayList<array> arrayList){
ArrayList<HashMap<String, String>> listMap = new ArrayList<HashMap<String,String>>();
for(int i = 0; i < rssArrayList.size(); i++){
map.put("writeDate", arrayList.get(i).getWriteDate());
map.put("title", arrayList.get(i).getTitle());
listMap[listNumber].add(map);
}
return listMap;
}