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

ExpandableListView 관련 질문입니다..

0 추천

 

어쩌다 안드로이드를 잠깐 코딩해야하는 상황이 와서요..

 

어렵게 어렵게 짜집기하면서 만들어보고있는데..쉽지가않네요^^;;;

 

ExpandableListView를 만드는데.. Child 리스트뷰는 하나씩만 만들고

 

그곳에 이미지뷰와 텍스트뷰를 이용하여 마치 공지사항 게시판처럼 꾸미려 합니다.

 

가져온 예제는 String배열에 넣은 글자만 출력하는거라서, 제가 추가한 ImageView는

 

어떤식으로 추가를 해줘야할지 상당히 막막하네요...ㅎㅎ

 

다른부분에서 Socket 통신을 구현해서 URL을 받아오는 식으로 구현중인데

 

해당 Child ListView에서 URL로 이미지를 출력하는 메소드랑 방법좀 알수있을까요?

 

아래는 소스입니다...

 

 

Java 소스파일 부분

 

package kops.nfcreading;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.ExpandableListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SimpleExpandableListAdapter;

public class NoticeActivity extends ExpandableListActivity {
    /** Called when the activity is first created. */
 public String[] group = {"공지사항1","공지사항2","공지사항3","공지사항4"};
 public String[][] child = {
   
   {"내용1\n"},
   {"내용2\n"},
   {"내용3\n"},
   {"내용4\n"},
   };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_notice);
      
        SimpleExpandableListAdapter adapter= new SimpleExpandableListAdapter(
          this,
          getGroupList(),
          R.layout.child_row,
          new String[]{"wordsName"},
          new int[]{R.id.childName},
          getChildList(),
          R.layout.child_row2,
          new String[]{"wordsContents"},
          new int[]{R.id.wordsContent}
        );
       
        this.setListAdapter(adapter);
    }
    public List getGroupList(){
     List groupList = new ArrayList<HashMap>();
     for(int i=0;i<group.length;i++){
      HashMap map = new HashMap();
      map.put("wordsName", group[i]);
      groupList.add(map);
   
     }
     return groupList;
    }
    public List getChildList(){
     List childList = new ArrayList<List>();
     for(int i=0;i<child.length;i++){
      List childchildList = new ArrayList<HashMap>();
      for(int k=0;k<child[i].length;k++){
       HashMap map = new HashMap();
       map.put("wordsContents", child[i][k]);
       childchildList.add(map);
      }
      childList.add(childchildList);
     }
     return childList;
    }
   
  }

 

 

 

 

 

Child_row.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"
  android:orientation="vertical"
  android:background="#00000000">

  <TextView
  android:id="@+id/childName" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textColor="#000000"
  android:textSize="20dip"
  android:paddingLeft="40dip"
  />
 
</LinearLayout>

 

 

 

 

Child_row2.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"
  android:orientation="vertical"
  android:background="#00000000">

    <ImageView
        android:id="@+id/notice_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/background2" />

  <TextView android:id="@+id/wordsContent" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textSize="15dip"
  android:textColor="#123456"
  android:paddingLeft="10px"
  />
</LinearLayout>

 

 

 

 

 

activity_notive.xml

 



<?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">
  
     <ExpandableListView android:id="@+id/android:list"
               android:layout_width="fill_parent"
         android:cacheColorHint="#00000000"
               android:layout_height="fill_parent"/>
 
     <TextView android:id="@+id/android:empty"
               android:layout_width="fill_parent"
  android:textColor="#000000"
               android:layout_height="fill_parent"
               android:text="no_item"/>
</LinearLayout>

 

 

Android.Park (120 포인트) 님이 2013년 5월 14일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...