-1

Every tutorial I've tried to follow thus far has tried to get me to use a LayoutInflator inside the getView() in my CustomAdapter.

The LayoutInflator does not turn up for me and I only get the options of LayoutInflatorCompat or LayoutFactory.

Can anyone help me take the data out of the user object I have created and set it to the 2 appropriate text fields in my rowlayout.xml?

I'm assuming this still needs to be done inside my getView() method inside my UserAdapter.

User only has 2 Strings, name and description. My rowlayout has tv_name, tv_description.

public class UserAdapter extends BaseAdapter {


ArrayList<user> list;
Context context;

public UserAdapter(Context c,ArrayList<user> list)
{
    context = c;
    this.list = list;

}

@Override
public int getCount() {
    return list.size();
}

@Override
public Object getItem(int position) {
    return list.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    return null;
}

}

1 Answers1

0

Inflate the desired layout into the convertView using the LayoutInflater and your Context and then you can use that to get the TextViews and set the text, something like this:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.your_layout, parent, false);
            TextView tvName = (TextView) convertView.findViewById(R.id.tv_name);
            TextView tvDescription = (TextView) convertView.findViewById(R.id.tv_description);

            User user = users.get(position);
            tvName.setText(user.getName());
            tvDescription.setText(user.getDescription());
        }
        return convertView;
    }
Jeffalee
  • 1,080
  • 1
  • 7
  • 15