뷰를 만들고 Java에서 프로그래밍 방식으로 속성을 설정할 수 있습니다. AWT/Swing 사용법과 거의 동일합니다.
public class MyAdapter extends BaseAdapter {
private List<String> items; // could be an array/other structure
// using Strings as example
public MyAdapter(Context context, List<String> items) {
this.context = context;
this.items = new ArrayList<String>(items);
}
public int getCount() {
return items.size();
}
// notice I changed the return type from Object to String
public String getItem(int position) {
return items.get(position);
}
public View getView(int position, View convertView, ViewGroup parent) {
// Really dumb implementation, you should use the convertView arg if it isn't null
TextView textView = new TextView(context);
textView.setText(getItem(position);
/* call other setters on TextView */
return textView;
}
}
당신은 다른 메소드를 오버라이드 (override) 할 수도 있지만 별다른 설명이 있어야한다.
ArrayAdapter 또는 CursorAdapter 문제가 무엇입니까? 컨벤션에 반대하는 귀하의 요구 사항을 명시하십시오. – CRUSADER
ArrayAdapter의 문제는 위에서 설명한대로이며 뷰 생성을 XML로 처리하고 싶지 않습니다. CursorAdapter를 사용하면 목록의 간단한 구현이 필요하므로 여기서는 SQL 데이터베이스를 다루지 않을 것입니다. – CodenameLambda1