Global It Leader!!



 
 

모바일 ListView에 addFooterView를 이용해서 more 추가하기

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 2,165회 작성일 14-08-30 01:44

본문

180697364FB1C9AD1AF57C



리스트뷰를 선언하고, 어댑터를 추가한다.

어댑터를 추가하기 전에 addFooterView를 추가해야한다.

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
32
33
34
35
36
37
38
39
40
41
public class Home extends Activity
{
    private final long MORE_CODE = -1;
    private ListView _listview;
    private String[] items = { "아이유", "김태희", "문근영", "임수정", "태연", "소연", "크리스탈", "효성" };
      
      
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
          
        _listview = (ListView) findViewById(R.id.listView1);
          
        // setAdapter 전에 추가해야한다
        View kMore = getLayoutInflater().inflate(R.layout.item_more, null);
        _listview.addFooterView(kMore, MORE_CODE, true);
          
        _listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
        _listview.setOnItemClickListener(onItemClickListener);
    }
      
    private OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int $pos, long $rid)
        {
            // BaseAdapter 를 상속해서 어댑터를 만든다면 getItemId에서 다른 값을 줘서 more_code를 다른 숫자로 바꿔서 사용가능하다 
            if ($rid == MORE_CODE)
            {
                Log.w("Home.onItemClickListener | onItemClick()", "clicked more");
            }
            else
            {
                Log.w("Home.onItemClickListener | onItemClick()", "clicked item");
            }
        }
    };
}




메인화면에 리스트뷰를 하나 넣는다.


1
2
3
4
5
6
7
8
9
10
11
12
     
<?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/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>
</LinearLayout>



more 도 하나의 행으로 추가가 되는거기 때문에 표시할 모양으로 리스소 파일을 하나 추가한다.


1
2
3
4
5
6
7
8
9
10
11
12
     
<?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:gravity="center" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="더 보기"
        android:textAppearance="?android:attr/textAppearanceLarge" />

댓글목록

등록된 댓글이 없습니다.

전체 79
게시물 검색
모바일세상 목록
번호 제목 글쓴이 조회 날짜
59 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2392 05-18
58 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1979 05-14
57 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1981 05-14
56 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5597 05-14
55 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2012 05-07
54 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2261 04-20
53 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2403 03-31
52 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2208 03-31
51 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2299 09-01
50 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2706 09-01
49 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1860 09-01
48 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1968 09-01
47 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2492 09-01
46 제이쿼리 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1985 09-01
45 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2146 08-31
44 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2014 08-31
43 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3616 08-31
열람중 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2166 08-30
41 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1987 08-30
40 모바일 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3259 08-29