我在android中的getView()中遇到错误?

时间:2016-08-01 05:16:09

标签: android

我有一个listview和自定义适配器....当我运行程序时,它会在getview中给我错误。如何解决该错误。

代码: -

public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
        viewHolder = new ViewHolder();
        convertView = View.inflate(m_Context, R.layout.deallisting_card_view, null);
        viewHolder.m_Header = (TextView) convertView.findViewById(R.id.headingText);
        viewHolder.m_Subheader = (TextView) convertView.findViewById(R.id.subHeaderText);
        viewHolder.m_DummyText = (TextView) convertView.findViewById(R.id.subHeadingText);
        viewHolder.m_logoImage = (ImageView) convertView.findViewById(R.id.appImage);
        viewHolder.m_getBtn = (Button) convertView.findViewById(R.id.getDealBtn);
        convertView.setTag(viewHolder);

    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
}

在此行的covertview = View.inflate(m_Context...);中我收到错误

2 个答案:

答案 0 :(得分:1)

这应该是这样做的。

var urlAppend;

function drawNewUrl() {
    if (jQuery(window).width() > 1200) {
        var urlAppend = '?url/suffix/example/3/';
    }  else if (jQuery(window).width() > 768) {
        var urlAppend = '??url/suffix/example/2/';
    } else {
        var urlAppend = '?url/suffix/example/1/';
    }

    jQuery('.class').attr('href', function() {
        return this.href + urlAppend;
    });
}
jQuery(window).resize(function() {
    jQuery(urlAppend).remove();
    drawNewUrl();
});
jQuery(document).ready(function() {
    drawNewUrl(); // for onload 
});

答案 1 :(得分:0)

public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder= new ViewHolder();
    vi=convertView;       
    LayoutInflater mInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {           
         vi= mInflater.inflate( R.layout.deallisting_card_view, null);
        viewHolder.m_Header = (TextView) convertView.findViewById(R.id.headingText);
        viewHolder.m_Subheader = (TextView) convertView.findViewById(R.id.subHeaderText);
        viewHolder.m_DummyText = (TextView) convertView.findViewById(R.id.subHeadingText);
        viewHolder.m_logoImage = (ImageView) convertView.findViewById(R.id.appImage);
        viewHolder.m_getBtn = (Button) convertView.findViewById(R.id.getDealBtn);
        convertView.setTag(viewHolder);

    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
}

尝试上面的代码,希望它能工作:)GlbMP