当我添加它正常工作的第一个项目,但是当我在文本框中添加:第二个它显示的ListView项的布局,但没有任何数据,如这些图片: ScreenShot 1, ScreenShot 2查看自定义列表视图项的Android
我的适配器代码:
public class Myadp extends ArrayAdapter<String> {
private String[] data;
Context context;
private static LayoutInflater inflater = null;
public Myadp(Context context, int resource, int textViewItem, String[] strings) {
super(context, resource, textViewItem, strings);
this.data = strings;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.listtemp, null, true);
TextView textView = (TextView) row.findViewById(R.id.textView2);
textView.setText(this.data[position]);
return row;
}}
我在Android Studio中几个月前开发的应用和我使用inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
代替inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
但现在Android的工作室不承认它
你应该解释为什么,而不仅仅是邮政编码。 – cyroxis
因为它不是再次使用膨胀行,他一次又一次地创建每一行。 –
我曾经使用inflater =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);但现在Android Studio不能识别它 –