listClass.add(new ListClass(json.getString("ProductId"), json
.getString("ProductPrice")));
}
list.setAdapter(new MyListAdapter(Fragment1.this, listClass));
Mais en classe: MyListAdapter Je reçois une erreur:Fragment au contexte?
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = LayoutInflater.from(fragment).inflate(
R.layout.pricelist, parent, false);
classe fragment1 étend fragment. Alors que dans rowView = layoutinflater.from (// je ne peux étendre le contexte ici et pas un fragment). Que puis-je faire ??
Mise à jour classe mylistadapter:
public class MyListAdapter extends BaseAdapter {
private Fragment fragment;
private ArrayList<ListClass> listClass = new ArrayList<ListClass>();
public MyListAdapter(Fragment1 fragment1, ArrayList<ListClass> listClass1) {
this.fragment = fragment1;
this.listclass = listClass1;
}
@Override
public int getCount() {
return listClass.size();
}
@Override
public Object getItem(int position) {
return ListClass.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = LayoutInflater.from(fragment).inflate(
R.layout.pricelist, parent, false);
TextView text1 = (TextView) rowView.findViewById(R.id.title);
TextView text2 = (TextView) rowView.findViewById(R.id.details);
text1.setText(BeanClass.get(position).phoneName);
text2.setText(BeanClass.get(position).phonePrice);
return rowView;
}
}
Utilisez ce 'list.setAdapter (nouvelle MyListAdapter (getActivity(), listclass))' – Raghunandan
Désolé i dactylographiées mauvais noms .. réparé (je reçois toujours une erreur). –
Vérifiez les documents http://developer.android.com/reference/android/app/Fragment.html – Raghunandan