2016-08-01 60 views
-3

我有一個列表視圖和自定義適配器....當我運行程序時,它會給我錯誤getview.How我可以解決這個錯誤。我在android中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...);

在此行中我得到錯誤

+0

調用'convertView = inflater.inflate(R.layout.deallisting_card_view,NULL);' –

+0

可以添加整個類 – DKV

+0

在這裏發佈錯誤日誌 –

回答

1

這應該這樣做。

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

    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    final ViewHolder viewHolder; 

    if (convertView == null) { 

     viewHolder = new ViewHolder(); 
     convertView = inflater.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(); 
    } 
} 
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