Code example for ListView

Methods: setAdapter, setOnItemClickListener

0
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        mListView = new ListView(this);
        mListView.setAdapter(new BaseAdapter() {
 
            @Override 
            public View getView(int position, View convertView, ViewGroup parent) {
                if (convertView == null) {
                    LayoutInflater li = LayoutInflater.from(MainActivity.this);
                    convertView = li.inflate(android.R.layout.simple_list_item_1, parent, false);
                } 
                TextView tv = (TextView)convertView.findViewById(android.R.id.text1);
                Class<?> cls = TESTS[position];
                tv.setText(cls.getSimpleName());
                convertView.setTag(cls);
                return convertView;
            } 
 
            @Override 
            public long getItemId(int position) {
                return position;
            } 
 
            @Override 
            public Object getItem(int position) {
                return TESTS[position];
            } 
 
            @Override 
            public int getCount() { 
                return TESTS.length;
            } 
        }); 
        mListView.setOnItemClickListener(new OnItemClickListener() {
 
            @Override 
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Class<?> cls = (Class<?>) view.getTag();
                Intent intent = new Intent(MainActivity.this, cls);