0

내 첫 번째 사용자 지정 어댑터를 만들어 내 안드로이드 응용 프로그램에 대한 목록보기를 생성하려고합니다. 나는 그것을 처리하고 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이다. 두 번째 줄에서

+0

사용 RecyclerView 더 많은 기능을 갖춘 물건을 호출합니다. http://www.androidhive.info/2016/01/android-working-with-recycler-view/ –

답변

0

당신은 당신의 자신의 어댑터 클래스를 만들

ListAdapter customAdapter = new ArrayAdapter<Person>(ByState.this, R.layout.bystate_itemview,personData); 

ListAdapter customAdapter = new ListAdapter(ByState.this, R.layout.bystate_itemview, personData); 

에 의해 대체하지만, STANDART ArrayAdapter와에게

+0

하지만 생성자가 컨텍스트를 사용하고 있고 내가 ByState.this를 주면 여전히 오류가 발생합니다. – Anirban

+0

@Anirban 귀하의 코드에서 알 수없는, ByState 무엇입니까. 이것이 컨텍스트 또는 활동이 아니면 먼저 발견하고 첫 번째 매개 변수로 사용하십시오. –

+0

ByState는 단편 – Anirban

관련 문제