我正在学习PageSlider并希望在我的幻灯片段中实现ListViews,我的代码如下,但在CustomAdapter上出错:
The constructor FragmentA.CustomAdapter(FragmentA, String[], String[], int[]) is undefined.
我可以添加TextView,但ListView会返回错误,如上所述。
FragmentA:
public class FragmentA extends Fragment {
String [] arrayName;
String [] arrayDescription;
int[] images = {R.drawable.img1, R.drawable.img2, R.drawable.img3};
ListView lv;
public FragmentA() {
//
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_a, container, false);
ListView lv =(ListView)view.findViewById(R.id.listView);
CustomeAdapter adapter = new CustomeAdapter (this, arrayName, arrayDescription, images); //Error: The constructor FragmentA.CustomAdapter(FragmentA, String[], String[], int[]) is undefined
lv.setAdapter(adapter);
return view;
}
CustomAdapter:
public class CustomeAdapter extends ArrayAdapter<String>
{
Context context;
String[] arraynames;
String[] arrayDescription;
int[] images;
CustomeAdapter(Context c, String [] name, String [] description, int img[])
{
super(c, R.layout.activity_lv_single, R.id.textname, name);
this.context=c;
this.arraynames=name;
this.arrayDescription=description;
this.images=img;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.activity_lv_single, parent, false)
}
TextView tvName = (TextView) rowView.findViewById(R.id.textName);
TextView tvDescription = (TextView) rowView.findViewById(R.id.textDesc);
ImageView ivImage = (ImageView) rowView.findViewById(R.id.img);
tvName.setText(arrayNames[position]);
tvDescription.setText(arrayDescription[position]);
ivImage.(images[positionl
return rowView;
}
}