-1
private void initializeListItems() {
// 1st item (position 0)
itemRepeatAlarm = new TextOnlyItem();
itemRepeatAlarm.setTitle(getString(R.string.repeat_weekly));
itemRepeatAlarm.setSubtitle(getString(R.string.never));
// add the 1st item to the list adapter
listAdapter.addItem(itemRepeatAlarm);
// 2nd item (position 1)
itemAlarmType = new TextOnlyItem();
itemAlarmType.setTitle(getString(R.string.alarm_type));
// set the default option to "sound", which is the first string value in the string array called 'sound_vibrate'.
itemAlarmType.setSubtitle(getResources().getStringArray(R.array.sound_vibrate)[0]);
// add the 2nd item to the list adapter
listAdapter.addItem(itemAlarmType);
// 3rd item (position 2)
itemAlarmTypeVolume = new VolumeSeekbarItem();
// add the 3rd item to the list adapter
listAdapter.addItem(itemAlarmTypeVolume);
// 4th item (position 3)
itemAlarmTone = new TextOnlyItem();
itemAlarmTone.setTitle(getString(R.string.alarm_tone));
itemAlarmTone.setSubtitle(getString(R.string.none));
// add the 4th item to the list adapter
listAdapter.addItem(itemAlarmTone);
// 5th item (position 4)
itemSnooze = new TextAndSwitchItem();
itemSnooze.setTitle(getString(R.string.snooze));
itemSnooze.setSubtitle(getString(R.string.snooze_details));
itemSnooze.check();
// add the 5th item to the list adapter
listAdapter.addItem(itemSnooze);
// 6th item (position 5)
itemAlarmName = new TextOnlyItem();
itemAlarmName.setTitle(getString(R.string.alarm_name));
itemAlarmName.setSubtitle(getString(R.string.none));
// add the 6th item to the list adapter
listAdapter.addItem(itemAlarmName);
// 7th item (position 6)
itemAlarmLock = new TextOnlyItem();
itemAlarmLock.setTitle(getString(R.string.alarm_lock));
// set the name of the first alarm lock option as default.
itemAlarmLock.setSubtitle(getResources().getStringArray(R.array.alarm_lock_list)[0]);
// add the 8th item to the list adapter
listAdapter.addItem(itemAlarmLock);
// notifyDataSetChanged() method belongs to the BaseAdapter class.
// Notifies the attached observers that the underlying data has been changed and
// any View reflecting the data set should refresh itself.
listAdapter.notifyDataSetChanged();
}
當我運行代碼時,其他人沒有任何問題。但第4項itemAlarmTone
沒有顯示字幕,我原本預計會有none
,因爲您可以通過下面的拍攝圖像瞭解到。Android:列表視圖中的一項不能正確顯示文本
正如我剛纔做了一個研究,到目前爲止,的合理原因的故障之一,是因爲列表項的佈局未設置有match_parent
他們的高度值。我已經研究過佈局,確定了價值,並且似乎仍然像上面那樣。