Reputation: 221
How can I create convertView manually in following method. I read that convertView can be created manually or inflated from xml file.
public View getView(int position, View convertView, ViewGroup parent)
I am using xml file for layout.
Upvotes: 0
Views: 355
Reputation: 275
You can use this code inside the override getView method while extending the ArrayAdapter Class
if(convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
}
R.layout.list_item is the resource to create the view based on.
the parameter "false" is false to weather to attach to the root.
Upvotes: 1
Reputation: 9258
Use View.inflate(context, resource, root);
@Override
public View getView(int position, View convertView, ViewGroup parent){
final View contentView = convertView != null ? convertView : View.inflate(context, resource, null);
}
where resource
is your xml layout resource id like R.layout.list_item
.
Something like that.
Upvotes: 1