Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 본인인증
- Spring Boot
- 컨퍼런스
- docker
- db
- ktlin
- Flux
- 로그인
- 인증
- 코틀린
- Spring
- API
- 허깅 페이스
- spring security
- 보안
- exception
- AOP
- 본인확인
- IntelliJ
- 딥시크
- Mono
- PostgreSQL
- postgis
- webflux
- deepseek vs chatgpt
- AWS
- 공동인증서
- NGINX
- netty
- Kotlin
Archives
- Today
- Total
[수미수의 개발 브로구]
[Android] ViewPager 안에 ListView 넣기 본문
반응형
개요
ViewPager 안에 여러 리스트뷰를 넣고자 할 때 아래와 같이 진행 한다.
따라하기
Activity 부분
- 먼저 리스트 뷰를 생성하고. 해당 리스트를 Vector로 관리한다. 그런다음, ViewPager 생성 시 ViewPagerAdapter에 해당 리스트 뷰의 Vector를 인자로 넘겨 ViewPagerAdapter를 생성한뒤 SetAdapter이 주입한다.
- 그리고, 해당 listView 적절한 아이템을 넣어 ListViewAdapter를 생성한 뒤, ListView에 주입한다.
private void MakeListView()
{
ListView listview1 = new ListView(this);
ListView listview2 = new ListView(this);
ListView listview3 = new ListView(this);
Vector<View> pages = new Vector<View>();
pages.add(listview1);
pages.add(listview2);
pages.add(listview3);
ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
CustomPagerAdapter adapter = new CustomPagerAdapter(this,pages);
vp.setAdapter(adapter);
listview1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,new String[]{"A1","B1","C1","D1","A1","B1","C1","D1","A1","B1","C1","D1","A1","B1","C1","D1"}));
listview2.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,new String[]{"A2","B2","C2","D2"}));
listview3.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,new String[]{"A3","B3","C3","D3"}));
}
Layout.xml
- Viewpager의 height 부분을 fill_parent로 정의한다.
..................
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:id="@+id/lifewather_type"
android:text="@string/lifeweather_type"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
</LinearLayout>
</LinearLayout>
..................
결과
- 위와 같이 할 경우, ViewPager에 각각의 리스트뷰가 생성되고, 해당 리스트뷰는 각각의 스크롤 기능을 가지게 된다.
반응형
'Language & Framework > Android' 카테고리의 다른 글
[Android] 안드로이드 Compose 란 (0) | 2024.12.24 |
---|---|
[Android] ViewPager 에서 Position 정보가 일치 하지 않을 때 (0) | 2023.09.28 |
[Android] Fragment 간 Image 전달 (0) | 2023.09.28 |
[Android] TextureView, SurfaceView (1) | 2023.09.28 |
[Android] SVG Image (0) | 2023.09.28 |