package com.example.ysgridproject;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
public class L2Adapter extends ArrayAdapter<String[]> {
ArrayList<String[]> items ;
Context context;
int FixCol ;
ArrayList<LinearLayout> L2a1bs = new ArrayList<LinearLayout>();
ArrayList<LinearLayout> L2a2bs = new ArrayList<LinearLayout>();
public L2Adapter(Context con, int textViewResourceId ,ArrayList<String[]> objects , int fixcol) {
super(con, textViewResourceId ,objects);
context=con;
items=objects;
FixCol = fixcol;
}
LinearLayout L2;
LinearLayout L2a1;
LinearLayout L2a2;
int mm = -1 ;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
System.out.println("converview = " + view);
if( view == null){
L2= new LinearLayout(context);
ListView.LayoutParams L2Param = new ListView.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
L2.setLayoutParams(L2Param);
L2a1 = new LinearLayout(context);
L2a2 = new LinearLayout(context);
LayoutParams L2a1Param = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT);
LayoutParams L2a2Param = new LayoutParams( (items.get(0).length-FixCol)*150+10 ,LayoutParams.MATCH_PARENT);
L2a1.setOrientation(LinearLayout.VERTICAL);
L2a2.setOrientation(LinearLayout.VERTICAL);
L2a1.setLayoutParams(L2a1Param);
L2a2.setLayoutParams(L2a2Param);
L2.addView(L2a1);
L2.addView(L2a2);
view = L2;
}
LinearLayout L2a1b = new LinearLayout(context); //L2a1b 매번 초기화 되기때문에 의미있게 L2a1b 에 담는다.
LayoutParams L2a1bParam = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
L2a1b.setLayoutParams(L2a1bParam);
L2a1b.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout L2a2b = new LinearLayout(context);
LayoutParams L2a2bParam = new LayoutParams((items.get(0).length-FixCol)*150+10 ,LayoutParams.WRAP_CONTENT);
L2a2b.setLayoutParams(L2a2bParam);
L2a2b.setOrientation(LinearLayout.HORIZONTAL);
for(int i = 0 ; i < FixCol ; i ++){ //content 내용 // ┌-------------------------┐
// │ │ │ │ │
TextView tvtitle = new TextView(context); // │ │ │ │ │
tvtitle.setText(items.get(position)[i]); // │ │ │ │ │
tvtitle.setWidth(150); // └-------------------------┘
tvtitle.setHeight(100);
tvtitle.setTextSize(20);
tvtitle.setGravity(Gravity.CENTER);
tvtitle.setBackgroundColor(Color.parseColor("#FFDAB9"));
L2a1b.addView(tvtitle);
}
for(int i = FixCol ; i < items.get(position).length ; i ++){
TextView tvtitle1 = new TextView(context);
tvtitle1.setText(items.get(position)[i]);
tvtitle1.setWidth(150);
tvtitle1.setHeight(100);
tvtitle1.setTextSize(20);
tvtitle1.setGravity(Gravity.CENTER);
tvtitle1.setBackgroundColor(Color.parseColor("#DAA520"));
L2a2b.addView(tvtitle1);
}
if(mm<position){ // getview 가 중복호출 됫을때 중복처리하지 않게 하기 위하여 position 마다 각각한번씩만 적용되도록한다.
L2a2bs.add(L2a2b); // L2ab(LinearLayout) 에 가로로 내용들을 담은 내용을 의미있게 List에 담는다.
L2a1bs.add(L2a1b);
System.out.println("L2a1bs.get("+(mm+1) +") 에 들어간다" );
L2a1.addView(L2a1bs.get((mm+1))); // 그 List 에들어있는 layout 중 position 에 해당하는 값만 addview
L2a2.addView(L2a2bs.get((mm+1)));
mm=position;
}
System.out.println("-----------------------------------------------");
return view;
}
}
검색안해본게아니라.. 다검색해봐도 뭐가먼지 2틀째 끙끙 거리고있습니다..
일단은 1차원배열을 List 로 받아서 뿌려주는 소스입니다
커스텀으로 LinearLayout 2개를 합쳐 하나의 레이아웃으로 만들어 리턴해주고있습니다
다출력은되는데 14개가 있다면 10개가 화면에보여지고 12개쯤부터는 view 를 새로 안만들고 재활용해서
사용하기때문에 첫번째 index가 13번째에 복사해서 붙여져있고 계속 스크롤하다보면 전체적으로 뒤죽박죽이 됩니다..
어떻게해결해야할까요... view 가 Null 이 아닐때를 구현해야할것 같은데 ..
방향을 못잡겠습니다.
재활용 뷰에 textview 를 가져와 settext 로 바꾸고싶은데 접근을못하겠어요 ..