Unable to start activity:UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

前端 未结 4 1416
南方客
南方客 2020-11-30 04:21

I want to write a ListView in basic format but I get an error:

UnsupportedOperationException: addView(View, LayoutParams) is not supported in Ad         


        
4条回答
  •  臣服心动
    2020-11-30 05:16

    Replace your layout in inflater

     @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
    
        if (convertView == null) {
    
            LayoutInflater inflater = (LayoutInflater) LayoutInflater
                    .from(contex);
            convertView = inflater.inflate(R.layout.your_layout, parent, false);
    
        }
    
        txtName = (TextView) convertView.findViewById(R.id.txtName);
        txtName.setText(""+ContactsArr.get(position).get("ContName"));
        txtPhoneNumber = (TextView) convertView.findViewById(R.id.txtContact);
        txtPhoneNumber.setText(""+ContactsArr.get(position).get("ContPhone"));
    
        return convertView;
    }
    

提交回复
热议问题