내 첫 번째 사용자 지정 어댑터를 만들어 내 안드로이드 응용 프로그램에 대한 목록보기를 생성하려고합니다. 나는 그것을 처리하고 ArrayList에에 저장 한 후 API 호출에서 내 데이터를 받고 오전 : -사용자 지정 어댑터에 대한 생성자 불일치
class Person{
String bioguide;
String image;
String lastname;
String firstname;
String district;
String state;
String party;}
public static ArrayList<Person> personData = new ArrayList<Person>();
를 지금은 다음과 같이 내 데이터를 표시하는 목록보기 및 사용자 정의 어댑터를 만들려고하고있는 onpostexecute 섹션에서 : -
ListView yourListView = (ListView) rootView.findViewById(R.id.state_listView);
ListAdapter customAdapter = new ArrayAdapter<Person>(ByState.this, R.layout.bystate_itemview,personData);
yourListView .setAdapter(customAdapter);
}
}
public class ListAdapter extends ArrayAdapter<Person> {
public ListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public ListAdapter(Context context, int resource, ArrayList<Person> items) {
super(context, resource, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.bystate_itemview, null);
}
Person p = getItem(position);
if (p != null) {
TextView tt1 = (TextView) v.findViewById(R.id.last_name);
TextView tt2 = (TextView) v.findViewById(R.id.first_name);
if (tt1 != null) {
tt1.setText(p.getLastname());
}
if (tt2 != null) {
tt2.setText(p.getFirstname());
}
}
return v;
}
}
}
나는 인터넷 자습서를 따라 위 코드를 받았습니다. 문제는 customadapter를 먼저 사용하여 custom adapter의 생성자를 호출하는 줄에 오류가 발생했습니다. 그것은 생성자를 해결할 수 없다고 말합니다. 누군가 이걸 이해하는데 나를 도울 수 있습니까? 나는 내 케이스에 대한 적절한 생성자를 정의하지 않았다는 것을 알고 변경 사항을 알려주십시오. 나는 조각 내부에 listview를 만들고 있는데, 조각 클래스 이름은 ByState이다. 두 번째 줄에서
사용 RecyclerView 더 많은 기능을 갖춘 물건을 호출합니다. http://www.androidhive.info/2016/01/android-working-with-recycler-view/ –