Android ListView实现任意layout
jopen
10年前
SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.timenotes_item_left, new String[] { "text1", "text2", "text3" }, new int[] { R.id.textView2, R.id.textView3, R.id.textView4 }) { @Override public View getView(int position, View convertView, ViewGroup parent) { Map itemData = (Map) getItem(position); int type = Integer.parseInt(itemData.get("type").toString()); View itemView = null; switch (type) { case 0: Log.d("adapter", "type 0"); itemView = View.inflate(getApplicationContext(), R.layout.timenotes_item_left, null); break; case 1: Log.d("adapter", "type 1"); itemView = View.inflate(getApplicationContext(), R.layout.timenotes_item_right, null); break; default: Log.d("adapter", "type default"); break; } return itemView; } }; ListView listView = (ListView) findViewById(R.id.listView1); listView.setAdapter(adapter);