int*_*thi 3 android android-adapter android-fragments
这是我的 getView() 方法。膨胀时出现空指针异常。同样的问题有很多答案。这在片段中使用。但这不适合我。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Context con = null;
View vi=convertView;
if(convertView==null){
LayoutInflater inflater = (LayoutInflater)con.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.stores_listview_layout, null);
}
TextView tv = (TextView)vi.findViewById(R.id.store_name);
tv.setText(storeData.get(position).get("merchantName"));
return vi;
}
Run Code Online (Sandbox Code Playgroud)
我在这里做的错误是什么?
更新:这有效!
View vi=convertView;
Context c = null;
if(convertView==null){
LayoutInflater inflater = getLayoutInflater(null);
vi = inflater.inflate(R.layout.stores_listview_layout, parent, false);
}
Run Code Online (Sandbox Code Playgroud)
LayoutInflater inflater = getLayoutInflater(null);
vi = inflater.inflate(R.layout.stores_listview_layout, parent, false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7349 次 |
| 最近记录: |