當我添加它正常工作的第一個項目,但是當我在文本框中添加:第二個它顯示的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不能識別它 –