맞춤 목록을 만드는 더 좋은 방법이 있습니까? 내 코드는 반응이 적은 목록을 만드는 것처럼 보입니다. ScrollView에 두 개의 ListView가 필요하기 때문에 표준 Android 목록을 사용할 수 없습니다. 일반적으로Android 사용자 정의 목록이 느림
ArrayList<TypeA> typeAList;
ArrayList<TypeB> typeBList;
@Override
int getViewTypeCount(){ return 2; } // means you have two different views from it
@Override
int getItemViewType(int position){
if (position>typeAList.size()) return 1;
return 0;
}
getView(int pos, View convertView, ViewGroup parent){
// Check the pos
if (getItemViewType(pos) == 0){
// Inflate view and bind for type A
}
else{
// Inflate view and bind for type B
}
}
: 동일한 레이아웃 목록에 필요한 경우
setContentView(R.layout.alertsview);
inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
topRows = new ArrayList<View>();
topLayout = (LinearLayout)findViewById(R.id.topListLayout);
topLayout.removeAllViews();
topRows.clear();
List<Camera> camList = new ArrayList<Camera>(SitesOrchestrator.getInstance().currentSite.cameraList);
for (int i = 0; i < camList.size(); i++)
{
Camera cam = camList.get(i);
View row = inflater.inflate(R.layout.cameraalertrow, null);
TextView name = (TextView)row.findViewById(R.id.cameraNameAlerts);
CheckBox chk = (CheckBox)row.findViewById(R.id.camAlertChk);
name.setText(cam.name);
chk.setChecked(cam.alertsEnabled);
chk.setOnCheckedChangeListener(this);
String index = Integer.toString(i);
chk.setTag(index);
topRows.add(row);
topLayout.addView(row);
}
camList가 실제로 작지 않은 한, 이는 항상 느리고 비효율적입니다. UI를 다시 생각해보고 두 개의 목록을 피하십시오. –