public class DongProject2Activity extends Activity {
public final int NP = 10; // 한 페이지에 출력할 리스트 갯수
public int m_nPage = 1; // 현재 페이지
public ListView m_lv = null;
public LinearLayout m_footer = null;
public LinearLayout mainButton = null;
int getIntentContentNumber; // 게시글 번호 받을 공간
String getIntentCommentCoutn; // 댓글 갯수 담을 공간
String getIntentCommentDepth; // 댓글 깊이
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
final MyArrayAdapter adapter = new MyArrayAdapter(this, m_szStrings, R.layout.row);
adapter.setCount(m_nPage, NP);
// 푸터 생성
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
m_footer = (LinearLayout) inflater.inflate(R.layout.list_cell_footer1main, null);
Button Comment = (Button) m_footer.findViewById(R.id.btnFooter);
m_lv = (ListView) findViewById(R.id.list);
// 리스트의 갯수가 출력할 리스트의 갯수보다 클 경우 푸터 생성
if (m_szStrings.length > NP) {
m_lv.addFooterView(m_footer, null, false);
}
m_lv.setAdapter(adapter);
Comment.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.v("log", "Comment ++++++++++++++++++++++ : " + v);
if (adapter.setCount(++m_nPage, NP)) {
adapter.notifyDataSetChanged();
}
}
});
}
/*
// ListView의 아이템이 클릭되면 호출되는 callback.
public void onListItemClick(ListView l, View v, int position, long id) {
// super.onListItemClick(l, v, position, id);
// Toast.makeText(this, list.get(position), Toast.LENGTH_SHORT).show();
// Log.v("log","onListItemClick ++++++++++++++++++++++");
// 댓글 보기 페이지로 넘어감
Intent intent = new Intent(this, commentView.class);
intent.putExtra("contentID", m_szStrings[position]); // 게시판 글 번호 담는 곳
intent.putExtra("commentCoutn", "1"); // 코멘트 갯수
intent.putExtra("commentdepth", "1"); // 코멘트 깊이
startActivity(intent); // 페이지 넘김
}
*/
class MyArrayAdapter extends ArrayAdapter {
// 생성자 내부에서 초기화
Context context = null;
int m_nCount = 0;
int m_nLayout = 0;
String[] m_szString = null;
// 생성자
MyArrayAdapter(Context context, String[] szString, int nLayout) {
super(context, R.layout.row, m_szStrings);
this.context = context;
m_szString = szString;
m_nLayout = nLayout;
}
// 어뎁터 카운트를 설정한다
public boolean setCount(int nPage, int nNp) {
// Log.v("log","setCount: ++++++++++++++++++++++++++++");
if (nPage != 0 && nNp != 0) {
m_nCount = nPage * nNp;
return true;
} else {
return false;
}
}
@Override
public int getCount() {
// Log.v("log","getCount: ++++++++++++++++++++++++++++");
if (m_nCount != 0) {
if (m_szString.length > m_nCount) {
return m_nCount;
} else {
//만약 xml 파싱을 할 경우 마지막 페이지가 호출 완료된 시점에서 푸터를 제거.
//m_lv.removeFooterView(m_footer);
return m_szString.length;
}
}
return 0;
}
@Override
public Object getItem(int position) {
return m_szString[position];
}
@Override
public long getItemId(int position) {
return position;
}
// ListView에서 각 행(row)을 화면에 표시하기 전 호출됨.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// LayoutInflater의 객체 inflater를 현재 context와 연결된 inflater로 초기화.
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
// inflator객체를 이용하여 \res\laout\row.xml 파싱
View row = (View) inflater.inflate(R.layout.row, null);
// 카테고리를 담을 공간
TextView Category = (TextView) row.findViewById(R.id.category);
Category.setText("[ " + "잡담" + " ]");
// 아이디를 담은 공간 생성
TextView inName = (TextView) row.findViewById(R.id.idname);
inName.setText(" " + "IDtest");
// TextView 객체 label을 row 객체 내부에 있는 R.id.label로 초기화
// 내용 담을 공간
TextView label = (TextView) row.findViewById(R.id.label);
// label에 텍스트 설정.
label.setText(" " + m_szStrings[position]);
// 커스터마이징 된 View 리턴.
return row;
}
};
private String[] m_szStrings = { "Abbaye de Belloc",
"Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu",
"Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler",
"Alverca", "Ambert", "American Cheese", "Ami du Chambertin",
"Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "Appenzell",
"Aragon", "Ardi Gasna", "Ardrahan", "Armenian String",
"Aromes au Gene de Marc", "Asadero", "Asiago", "Aubisque Pyrenees",
"Autun", "Avaxtskyr", "Baby Swiss", "Babybel",
"Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal",
"Banon", "Barry's Bay Cheddar", "Basing", "Basket Cheese",
"Bath Cheese", "Bavarian Bergkase", "Baylough", "Beaufort",
"Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese",
"Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir",
"Bierkase", "Bishop Kennedy", "Blarney", "Bleu d'Auvergne",
"Bleu de Gex", "Bleu de Laqueuille" };
}
리스트뷰에 footer를 붙여서 더보기 기능을 구현했습니다.
기능은 잘 돌아가는데 더보기를 계속 클릭해서 리스트를 완전히 펼친 후 스크롤을 위아래로 왔다 갔다 몇 번 하면 outOfMemory 오류가 나는데 이유 알 수 있을까요?