私の最初のカスタムアダプタを作成して、アンドロイド用のリストビューを生成しようとしています。私は、API呼び出しから自分のデータを取得し、それを処理し、ArrayListの中でそれを格納しています: -カスタムアダプタのコンストラクタの不一致
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を最初に使用する行でエラーが発生していることです。それはコンストラクタを解決することはできません。誰かがこれを理解するのを助けることができますか?私は私のケースのために適切なコンストラクタを定義していないことを知っている私に変更を知らせてください。私はフラグメント内にリストビューを作成しており、フラグメントクラス名はByStateです。 2行目
使用RecyclerView、より多くの機能を備えたものArrayAdapterスタンダールを呼び出す
によって
を交換してください。 http://www.androidhive.info/2016/01/android-working-with-recycler-view/ –