如何在片段中添加BaseAdapter的Listview?

时间:2016-05-16 18:48:17

标签: java android listview android-fragments

我想在使用扩展ListView的自定义适配器的Fragment中添加BaseAdapter。 我不想通过ListFragment尝试它,因为我已经在那个片段中篡改了很多代码。 你能帮我在ListView中添加Fragment

adapter = new MyTableAdapter(getActivity(), list);
list.setAdapter(adapter);

和适配器类

public class MyTableAdapter extends BaseAdapter {
    List<Root.StandingBean> list;
    Activity context;

    public MyTableAdapter(Activity context, List<Root.StandingBean> list) {
        this.context = context;
        this.list = list;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.table_adapter, parent, false);
        TextView name = (TextView) rowView.findViewById(R.id.name);
        TextView pos = (TextView) rowView.findViewById(R.id.pos);
        TextView points = (TextView) rowView.findViewById(R.id.points);
        name.setText(list.get(position).getTeamName());
        pos.setText(String.valueOf(position));
        points.setText(String.valueOf(list.get(position).getPoints()));
        return rowView;
    }
}

0 个答案:

没有答案