Code example for Hashtable

Methods: get, keySet

0
	} 
 
	/** returns the key for the table, not the value (which is another table) */ 
	@SuppressWarnings("unchecked") 
	public Object getItem(int i) {
		Object[] array =_data.keySet().toArray();
		Arrays.sort(array, new SongComparator());
		Object retval = array[i];
		return retval;
	} 
 
	/** returns the unique id for the given index, which is just the index */ 
	public long getItemId(int i) {
		return i;
	} 
 
	/** 
	 * called when item in listview is selected... fires a model changed event... 
	 * 
	 * @param index index of item selected in listview. if -1 then it's unselected. 
	 */ 
	public void setSelected(int index) {
		if (index == -1) {
			// unselected 
		} else { 
			// selected index... 
		} 
		_selectedIndex = index;
		// notify the model that the data has changed, need to update the view 
		notifyDataSetChanged();
	} 
 
	public View getView(int index, View cellRenderer, ViewGroup parent) {
		CellRendererView cellRendererView = null;
		if (cellRenderer == null) {
			// create the cell renderer 
			cellRendererView = new CellRendererView();
		} else { 
			cellRendererView = (CellRendererView) cellRenderer;
		} 
		// update the cell renderer, and handle selection state 
		cellRendererView.display(index, _selectedIndex == index);
		return cellRendererView;
	} 
 
 
	private class CellRendererView extends TableLayout {
		// ui stuff 
		private TextView _lblSong;
 
		public CellRendererView() { 
			super(_context);
			_createUI(); 
		} 
 
		/** create the ui components */ 
		private void _createUI() { 
 
			// make the 2nd col growable/wrappable 
			setColumnShrinkable(1, true);
			setColumnStretchable(1, true);
 
			// set the padding 
			setPadding(10, 10, 10, 10);
 
			// single row that holds icon/flag & name 
			TableRow row = new TableRow(_context);
			LayoutUtils.Layout.WidthFill_HeightWrap.applyTableLayoutParams(row);
 
			// fill the first row with: icon/flag, name 
			{ 
				_lblSong = new TextView(_context);
				LayoutUtils.Layout.WidthWrap_HeightWrap.applyTableRowParams(_lblSong);
				_lblSong.setPadding(10, 10, 10, 10);
 
				//_lblIcon = AppUtils.createImageView(_context, -1, -1, -1); 
				//LayoutUtils.Layout.WidthWrap_HeightWrap.applyTableRowParams(_lblIcon); 
				//_lblIcon.setPadding(10, 10, 10, 10); 
 
				//row.addView(_lblIcon); 
				row.addView(_lblSong);
			} 
 
			/* 
			// create the 2nd row with: description 
			{ 
				_lblDescription = new TextView(_context); 
				LayoutUtils.Layout.WidthFill_HeightWrap.applyTableLayoutParams(_lblDescription); 
				_lblDescription.setPadding(10, 10, 10, 10); 
			} 
			 */ 
 
			// add the rows to the table 
			addView(row);
		} 
 
		/** update the views with the data corresponding to selection index */ 
		public void display(int index, boolean selected) {
 
			String id = getItem(index).toString();
			Map<String, String> song = _data.get(id);
			String artist = song.get(":artist");
			String title = song.get(":title");
			if ((artist == null) || (title == null)) {
				if ((artist == null) && (title == null))
					_lblSong.setText("");