먼저이에 대한 CustomAdapter를 만들어야합니다
public class CustomAdapter extends BaseAdapter {
ArrayList<View> views;
Context context;
public CustomAdapter(Context context, ArrayList<View> views){
this.views = views;
this.context = context;
}
@Override
public int getCount() {
return views.size();
}
@Override
public Object getItem(int i) {
return i;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View rowView = views.get(i);
/*set the views of the rowView here but take note use try catch since you can't be sure if the view will be present or not this is the part where I do not advice it to have different custom views per row but it's all yours to do your tricks*/
return rowView;
}
}
을 그리고 그것을 여기 내 샘플 방식의 사용을 만들 :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
ArrayList<View> views = new ArrayList<View>();
CustomAdapter adapter = new CustomAdapter(MainActivity.this,views);
ListView custom_list = (ListView)findViewById(R.id.list_custom);
custom_list.setAdapter(adapter);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view1 = inflater.inflate(R.layout.view1, null);
View view2 = inflater.inflate(R.layout.view2, null);
views.add(view1);
views.add(view2);
adapter.notifyDataSetChanged();
}
필요하다면 해결 방법을 취하지 만 기본적으로 이는 단지 문제입니다. 뷰를 확대하고 arrayList에 전달한 다음 listView에 설정합니다.
하나의 listview와 하나의 Custom 어댑터가 케이스를 기반으로 다른보기 (xml)를 부 풀리는 가장 좋은 방법입니다. –
yupp u 이렇게하면 다른 xmls을 팽창시킬 수 있습니다. – Shubham
사용자 정의보기가이를 해결할 수 있으며 단일보기로 여러 어댑터를 사용할 수 없습니다. 그것은 다른 어댑터를 대체 할 것입니다. – KaHeL