Database listview how to relate to the DB record

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Re: Database listview how to relate to the DB record

Postby Mark Worsnop » Mon Dec 06, 2010 6:10 pm

Shoot that doesnt work. Says

The type DatabaseAdapter cannot extend or implement ArrayAdapter<?>. A supertype may not specify any wildcard

Syntax: [ Download ] [ Hide ]
Using javascript Syntax Highlighting
  1.  
  2. public class DatabaseAdapter extends ArrayAdapter<?> {
  3.    
  4.     private Context mContext;
  5.     private ArrayList<?> mItems;
  6.     private int mXmlId;
  7.            
  8.     public DatabaseAdapter(Context context, int textViewResourceId, ArrayList<?> items) {
  9.             super(context, textViewResourceId, items);
  10.             this.mContext = context;
  11.             this.mItems = items;
  12.             this.mXmlId = textViewResourceId;
  13.     }
  14.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
Mark Worsnop
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Dec 01, 2010 12:34 am

Top

Re: Database listview how to relate to the DB record

Postby Mark Worsnop » Mon Dec 06, 2010 6:45 pm

Actually GRP is all over this code, not sure how to make it generic.

Also in the GetView its looking specifically for the "description" field. I guess I best make a new class like this for each set of tables.

Syntax: [ Download ] [ Hide ]
Using javascript Syntax Highlighting
  1. public class DatabaseAdapter extends ArrayAdapter<Grp> {
  2.    
  3.     private Context mContext;
  4.     private ArrayList<Grp> mItems;
  5.     private int mXmlId;
  6.            
  7.     public DatabaseAdapter(Context context, int textViewResourceId, ArrayList<Grp> items) {
  8.             super(context, textViewResourceId, items);
  9.             this.mContext = context;
  10.             this.mItems = items;
  11.             this.mXmlId = textViewResourceId;
  12.     }
  13.  
  14.  
  15.  
  16.     @Override
  17.     public View getView(final int position, View convertView, ViewGroup parent) {
  18.             View v = convertView;
  19.             if (v == null) {
  20.                     LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  21.                     v = vi.inflate(mXmlId, null);
  22.             }
  23.             Grp mo = mItems.get(position);
  24.             if (mo  != null) {
  25.                     TextView text = (TextView) v.findViewById(R.id.myTextView);
  26.                     if (text != null) {
  27.                             if(mo .getDescription() != null){
  28.                                     text .setText(mo .getDescription());
  29.                             }
  30.                     }              
  31.             }
  32.             return v;
  33.     }
  34. }
  35.  
Parsed in 0.006 seconds, using GeSHi 1.0.8.4
Mark Worsnop
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Dec 01, 2010 12:34 am

Re: Database listview how to relate to the DB record

Postby blundell » Mon Dec 06, 2010 8:20 pm

Yeah exactly, here's the project I promised :-)
CustomListView.rar
Custom ListView Ex
(27.65 KiB) Downloaded 77 times
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Database listview how to relate to the DB record

Postby Mark Worsnop » Mon Dec 06, 2010 9:20 pm

Super thank you! I wish i had this yesterday :)

So you agree that this is not a generic class and can only be used for the specific MyObject

Is that correct?
Mark Worsnop
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Dec 01, 2010 12:34 am

Re: Database listview how to relate to the DB record

Postby blundell » Mon Dec 06, 2010 10:03 pm

Yes as it only handles one type of List.
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 7 guests