开发者

Creating View manually

开发者 https://www.devze.com 2023-02-17 04:47 出处:网络
How can I create convertView manually in following met开发者_StackOverflow社区hod. I read that convertView can be created manually or inflated from xml file.

How can I create convertView manually in following met开发者_StackOverflow社区hod. 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消