@Override public View getView(int position, View convertView, ViewGroup parent) { View itemView = convertView; if (itemView == null) itemView = getActivity().getLayoutInflater().inflate(R.layout.textcar, parent, false); CNews currentNews = NewsItem.get(position); ((TextView) itemView.findViewById(R.id.News_txtTitle)).setText(currentNews.getNTitle()); ((TextView) itemView.findViewById(R.id.News_txtdate)) .setText(currentNews.getNStartDate() + "~" + currentNews.getNEndDate()); return itemView; }
private void NewsAdapterList() { // 外部類別 NewsItem.clear(); NewsTitle.clear(); for (CNews cNews : newsFactory.getAll()) { NewsItem.add(cNews); } for (CNews c : newsFactory.getAll()) { NewsTitle.add(c.getNTitle()); } ArrayAdapter<CNews> adapter = new NewsAdapter(); // listView.setAdapter(adapter); // 設定 ListView 的接收器, 做為選項的來源 listViewOnClick(); // 設onclick 事件 }