我使用類對象在列表視圖中添加了具有事件名稱,開始和時間的生命事件,但仍未成功;我有很多搜索,但無法找到相關答案。我是一個初學者希望大家幫我謝謝通過類對象動態地在列表中插入項目
public class MeetingFragment extends Fragment {
List<Meetings> meetingList; //here Meetings is a Class
Meetings newMeeting;
ListView listView;
String meetingTag;
String[] meetings;
ArrayAdapter<Meetings> adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_meeting, container,
false);
newMeeting = new Meetings();
listView = (ListView) rootView.findViewById(R.id.list_meetings);
meetings = new String[] {};
adapter = new ArrayAdapter<Meetings>(getActivity(), R.layout.list_item,
R.id.meeting_name);
listView.setAdapter(adapter);
});
//This is custom dialog
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String tagMeeting = et.getText().toString();
String startTimeStr = strtTime.getText().toString();
String endTimeStr = endTime.getText().toString();
newMeeting.setMeetingName(tagMeeting);
newMeeting.setStartTime(startTimeStr);
newMeeting.setEndTime(endTimeStr);
//Display error on below line
meetingList.add(newMeeting);
addMeeting.dismiss();
}
});
你有什麼錯準確..添加Logcat並縮小你的問題。 – Dhina