Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. private ListView lv;
  2. private String[] data = {"one", "two", "three"}
  3.  
  4. ..onCreate(){
  5.  
  6. }
  7.  
  8.  
  9.  
  10.   ...
  11.   lv = (ListView) findViewByID(R.id.lv);
  12.   BaseAdapter a = new BaseAdapter(){
  13.  
  14.     @Override
  15.     public int getCount(){}
  16.  
  17.     @Override
  18.     public Object getItem(int position){
  19.       return data[position];
  20.     }
  21.  
  22.     @Override
  23.     public long getItemId(int position){
  24.       return 0;
  25.     }
  26.  
  27.  
  28.     @Override
  29.     public View getView(int position, View convertView, ViewGroup parent){
  30.       if(convertView==null) convertView = new TextView(MainActivity.this);
  31.       TextView tv = (TextView) convertView;
  32.       tv.setText(data[position]);
  33.       // I am going to create a new class only if have nothing to recycle
  34.       // and I fill my views with the proper piece of elements
  35.       return tv;
  36.     }
  37.  
  38.    
  39.   }
  40.  
  41.   lv.setAdapter(a);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement