0
我有一個ListView應該是其樣式已定義在我的自定義適配器中的列表。但是,當我打開ListActivity
時,我得到一個空白的活動。列表不工作的自定義適配器
適配器代碼:
public class alarmListCustomAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
Typeface Light;
public alarmListCustomAdapter(Context context, String[] values, String font) {
super(context, R.layout.alarmlist_layout);
this.context = context;
this.values = values;
Light = Typeface.createFromAsset(context.getAssets(), font);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.alarmlist_layout, parent, false);
TextView tV1 = (TextView) rowView.findViewById(R.id.alarm_time);
TextView tV2 = (TextView) rowView.findViewById(R.id.alarm_label);
tV2.setText(values[position]);
return rowView;
}
}
ListActivity
代碼 -
public class alarmList extends ListActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
// use your custom layout
alarmListCustomAdapter adapter = new alarmListCustomAdapter(this, values, "fonts/Lato-Light.ttf");
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}
我沒有收到我的logcat的任何警告或錯誤。什麼可能會出錯?
我試圖通過here瞭解自定義適配器的實現。
你也可以建議他刪除視圖膨脹的邏輯,因爲超級會去照顧它。 – Blackbelt
@blackbelt是的,我一直忘記那一點,你指出了以前的一個類似的職位 – Raghunandan
@Raghunandan如何刪除充氣機?如果沒有它,'findViewbyID'似乎不起作用。 –