Advertisement
Guest User

MyAdapter.java

a guest
May 22nd, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. package ch.futurecom.adaptertest;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import android.app.Activity;
  6. import android.content.Context;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.ArrayAdapter;
  11. import android.widget.RelativeLayout;
  12. import android.widget.TextView;
  13.  
  14. public class MyAdapter extends ArrayAdapter<String>
  15. {
  16.     private Activity _context;
  17.     private ArrayList<String> _set;
  18.  
  19.     public MyAdapter(Activity context, ArrayList<String> set)
  20.     {
  21.         super(context, R.layout.row, R.id.txt, set);
  22.        
  23.         _context = context;
  24.         _set = set;
  25.     }
  26.    
  27.     @Override
  28.     public View getView(int position, View convertView, ViewGroup parent)
  29.     {
  30.         RelativeLayout view = (RelativeLayout) convertView;
  31.         TextView txt;
  32.        
  33.         if(convertView == null){
  34.             LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  35.             view = (RelativeLayout) inflater.inflate(R.layout.row, null);
  36.         }
  37.        
  38.         txt = (TextView) view.findViewById(R.id.txt);
  39.         txt.setText(_set.get(position));
  40.         System.out.println(txt.getText());
  41.        
  42.         return view;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement