마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

리스트뷰안에 리스트뷰 찾기

0 추천
Handler handler_kublah_comment = new Handler(){
		public void handleMessage(Message msg){
			commenthm = xml2HashMap(commentData,"UTF-8");
			
			//final ListViewHolder listviewHolder = new ListViewHolder(); 사용하지 않았음
			//listviewHolder.commentListview = (ListView) act.findViewById(R.id.kublah_comment_list); 
			
			commentListAdapter commentlistAdapter = new commentListAdapter(act,R.layout.kublah_comment_layout,commenthm); // the layout for the list view is added
			ListView commentlistView = (ListView) act.findViewById(R.id.kublah_comment_list);
			commentlistView.setAdapter(commentlistAdapter); //null pointer error
		};
	};

리스트뷰안에 들어있는 리스트뷰에다 다음과 같이 어뎁터를 이용해 레이아웃을 합성해주려고 합니다.

마지막줄

commentlistView.setAdapter(commentlistAdapter); //null pointer error

요기서 널포인터 에러가 나는거 보니

 

 

commentListAdapter commentlistAdapter = new commentListAdapter(act,R.layout.kublah_comment_layout,commenthm);
ListView commentlistView = (ListView) act.findViewById(R.id.kublah_comment_list);
요 두줄 중에 한 줄에서 kublah_comment_list를 못찾고 있는 것 같습니다.
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/kublah_top"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#FFBB00" >

        <ImageButton
            android:id="@+id/kublah_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:src="@android:drawable/alert_dark_frame" />

        <ImageButton
            android:id="@+id/kublah_drawer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@android:drawable/alert_light_frame" />

        <ImageButton
            android:id="@+id/kublah_write"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:src="@android:drawable/alert_light_frame" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/kublah_top" >
        
        <ListView
	        android:id="@+id/kublah_contentlist"
	        android:layout_width="match_parent"
	        android:layout_height="match_parent"
	        android:layout_centerHorizontal="true" >
    	</ListView>
    </RelativeLayout>
</RelativeLayout>

메인 xml파일안에 리스트뷰가 있고

그 리스트 뷰 안에 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/kublah_row_layout" >
    
	<LinearLayout 
	    android:layout_width="match_parent"
    	android:layout_height="wrap_content"
    	android:id="@+id/kublah_nameLayout">

		<TextView
		    android:id="@+id/kublah_name"
		    android:layout_width="wrap_content"
		    android:layout_height="wrap_content"
		    android:text="Name" />

	</LinearLayout>
	<LinearLayout 
	    android:id="@+id/kublah_textLayout"
	    android:layout_width="match_parent"
    	android:layout_height="wrap_content"
    	android:layout_below="@id/kublah_nameLayout">
	    <TextView
        android:id="@+id/kublah_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="kublah Text" />
	</LinearLayout>
	
	<RelativeLayout 
	    android:id="@+id/kublah_commentBtnLayout"
	    android:layout_width="match_parent"
    	android:layout_height="wrap_content"
    	android:layout_below="@id/kublah_textLayout">
	        
	        <ImageButton
	        android:id="@+id/kublah_commentRequestBtn"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:layout_alignParentRight="true"
	        android:layout_alignParentTop="true"
	        android:src="@android:drawable/alert_dark_frame" 
	        android:background="#00000000"/>    

	</RelativeLayout>
	<FrameLayout 
	    android:id="@+id/kublah_comment_showFrame"
        android:layout_width="match_parent"
    	android:layout_height="wrap_content"
    	android:layout_below="@id/kublah_commentBtnLayout">
        
        <TextView
        android:id="@+id/test_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

        <ListView
            android:id="@+id/kublah_comment_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>
        
    </FrameLayout>  
	
	<RelativeLayout 
	    android:id="@+id/kublah_comment_insertBtnLayout"
	    android:layout_width="match_parent"
    	android:layout_height="wrap_content"
    	android:layout_below="@id/kublah_comment_showFrame">

	    <ImageButton
	        android:id="@+id/comment_activationBtn"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:layout_alignParentTop="true"
	        android:layout_alignParentRight="true"
	        android:src="@android:drawable/alert_light_frame"
	        android:background="#00000000" />

	    <ImageButton
	        android:id="@+id/comment_insertBtn"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:layout_toLeftOf="@id/comment_activationBtn"
	        android:src="@android:drawable/arrow_up_float" />

	    <EditText
	        android:id="@+id/comment_here"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:layout_alignParentLeft="true"
	        android:layout_alignParentTop="true"
	        android:hint="comment here"
	        android:ems="10" >
	        <requestFocus />
	    </EditText>
	</RelativeLayout>
</RelativeLayout>

다음과 같은 리스트뷰가 삽입되어 있어 

이 리스트뷰에 내용을 출력한 후

큰 리스트뷰 상에 출력을 해주려고 합니다.

이렇게 두개의 리스트 뷰를 사용하는 경우 어떻게 구성을 해야하는지 알려주시면ㅜ

감사하겠습니다^^;;

 

우오오옹 (340 포인트) 님이 2013년 3월 3일 질문

1개의 답변

0 추천

kublah_comment_list

이녀석은 아마도 상위 리스트뷰에서 getview에서 리턴받는뷰에 있을테니 getview에서

잡아서 처리하셔야겠는데..

근데.. 리스트뷰에 리스트뷰는... 않좋은구조라고알고있습니다만..

건방진프로그래머 (26,630 포인트) 님이 2013년 3월 3일 답변
왜 안좋은 구조이죠..? 페이스북 뉴스피드 형식으로 댓글이 리스트뷰로 보여지게 하려고 하는데요.. 그럼 어떻게 해야될까요?
리스트뷰안에 리스트뷰가 들어가면 스크롤할때 오작동이 일어날 우려가있죠
그리고 페북아무리봐도 리스트뷰 하나인데요?
게다가 댓글눌르면 팝업형식으로 또 따로 리스트뷰가 뜨고요.. 그게
리스트뷰내에서의 리스트뷰라고 생각하시는건 아니시겠죠?
...