ListView 非自定义Adapter

public class ReportPriceListActivity extends Activity {
	ListView taskListView;
	List<Map<String, Object>> date;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.reportpricelist);

		InitView();
		date = getList();
		SimpleAdapter adapter = new SimpleAdapter(this, date,
				R.layout.listreportpricetask, new String[] { "taskname",
						"publishdate", "guid" }, new int[] { R.id.taskname,
						R.id.publicdate, R.id.guid });
		taskListView.setAdapter(adapter);

		taskListView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// ViewHolder holder = (ViewHolder) view.getTag();
				// String string=arg1.get
				// String string = holder.file_name.getText().toString();
				// Intent intent = new Intent(ReportPriceListActivity.this,
				// ReportPrice.class);
				// startActivity(intent);

			}
		});

	}

	private void InitView() {
		taskListView = (ListView) findViewById(R.id.tasklist);
	}

	// 测试数据
	private List<Map<String, Object>> getList() {
		List<ReportPriceList> reportPriceLists = new ArrayList<ReportPriceList>();

		ReportPriceList reportPriceList = new ReportPriceList();
		reportPriceList.setGuid("1");
		reportPriceList.setTaskname("测试任务1");
		reportPriceList.setPublishdate("2011-9-8");
		reportPriceLists.add(reportPriceList);

		reportPriceList = new ReportPriceList();
		reportPriceList.setGuid("2");
		reportPriceList.setTaskname("测试任务1");
		reportPriceList.setPublishdate("2011-9-8");
		reportPriceLists.add(reportPriceList);

		List<Map<String, Object>> mData;
		mData = new ArrayList<Map<String, Object>>();

		for (int i = 0; i < reportPriceLists.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("taskname", reportPriceList.getTaskname());
			map.put("publishdate", reportPriceList.getPublishdate());
			map.put("guid", reportPriceList.getGuid());
			mData.add(map);
		}

		return mData;
	}

}

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:layout_height="wrap_content">
	<TextView android:id="@+id/taskname" android:layout_width="wrap_content"
		android:textSize="17sp" android:layout_height="wrap_content" />
	<TextView android:id="@+id/publicdate" android:layout_width="wrap_content"
		android:textSize="17sp" android:layout_height="wrap_content" />
	<TextView android:id="@+id/guid" android:layout_width="0dp"
		android:layout_height="0dp" />
</LinearLayout>

 

你可能感兴趣的:(ListView)