ListView - 데이터 포인트 코드 자동 로드

3015 단어 ListView
private List<Map<String, Object>> data;
//       、
  loadingView = LayoutInflater.from(this).inflate(
    R.layout.list_page_load, null);
//       

	public class ListViewAdapter extends BaseAdapter {
		int count = data.size();

		public final class ListItemView {//        
			public TextView thread_number;
			public TextView thread_author;
			public TextView thread_time;
			public TextView thread_text;
		}

		public int getCount() {
			return count;
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			ListItemView listItemView = null;
			final int index = position;
			if (convertView == null) {
				listItemView = new ListItemView();
				convertView = LayoutInflater.from(ThreadDetailsActivity.this)
						.inflate(R.layout.forum_threaddetails_item, null);
				listItemView.thread_number = (TextView) convertView
						.findViewById(R.id.thread_number);
				listItemView.thread_author = (TextView) convertView
						.findViewById(R.id.thread_author);
				listItemView.thread_time = (TextView) convertView
						.findViewById(R.id.thread_time);
				listItemView.thread_text = (TextView) convertView
						.findViewById(R.id.thread_text);

				convertView.setTag(listItemView);

			} else {
				listItemView = (ListItemView) convertView.getTag();
			}
			listItemView.thread_number.setText((String) data.get(position).get(
					"thread_number"));
			listItemView.thread_author.setText((String) data.get(position).get(
					"thread_author"));
			listItemView.thread_time.setText((String) data.get(position).get(
					"thread_time"));
			listItemView.thread_text.setText((String) data.get(position).get(
					"thread_text"));

			return convertView;
		}
	}

 
	public static List<Map<String, Object>> initValue(int currentPage,
			int pageSize) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (int i = (currentPage - 1) * pageSize; i < currentPage * pageSize; i++) {
			HashMap<String, Object> win = new HashMap<String, Object>();
			win.put("thread_number", (i+1)+" ");
			win.put("thread_author", "   ");
			win.put("thread_time", "10-12 08:23");
			win.put("thread_text", "                           ");
			list.add(win);
		}
		return list;
	}

좋은 웹페이지 즐겨찾기