Code example for ListView

Methods: setAdapter, setLayerType

0
        findViewById(R.id.list1).setAlpha(1.0f);
    } 
     
    private void setupList(int listId) {
        final ListView list = (ListView) findViewById(listId);
        list.setAdapter(new SimpleListAdapter(this));
        list.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } 
 
    private static class SimpleListAdapter extends ArrayAdapter<String> {
        public SimpleListAdapter(Context context) {
            super(context, android.R.layout.simple_list_item_1, DATA_LIST);
        } 
 
        @Override 
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView v = (TextView) super.getView(position, convertView, parent);
            final Resources r = getContext().getResources();
            final DisplayMetrics metrics = r.getDisplayMetrics();
            v.setCompoundDrawablePadding((int) (6 * metrics.density + 0.5f));
            v.setCompoundDrawablesWithIntrinsicBounds(r.getDrawable(R.drawable.icon),