Wie BaseAdapter erweitern ?

  • Antworten:2
Mac Systems
  • Forum-Beiträge: 1.727

09.07.2009, 11:38:34 via Website

1public class SpotOverviewAdapter extends BaseAdapter
2{ private final Context context; private final List<SpotConfigurationVO> spotList; private final int rowResID;
3 /** * * @param _context * @param _rowResID * @param _spotList */ public SpotOverviewAdapter(final Context _context, final int _rowResID, final List<SpotConfigurationVO> _spotList) { context = _context; rowResID = _rowResID; spotList = _spotList; }
4 public int getCount() { return spotList.size(); }
5 public Object getItem(int position) { return spotList.get(position); }
6 public long getItemId(int position) { return position; }
7 public View getView(int position, View convertView, ViewGroup parent) { final SpotConfigurationVO weather = spotList.get(position);
8 final View view = View.inflate(context, rowResID, parent); view.setBackgroundColor(Color.BLUE); // ViewInflate inflate = ViewInflate.from(context); // View v = inflate.inflate(rowResID, parent, false, null); // TextView cityControl = (TextView) v.findViewById(R.id.city);
9 return view; }
10}



Folgender Code schmeißt mir grundsätzlich folgende Exception: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

Da ich meine verstanden zu haben wie Adapter zu benutzten sind sollte folgendes Layout funktionieren:


1<?xml version="1.0" encoding="UTF-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
3 <TextView android:id="@+id/custom_spotoverview_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="20sp" />
4 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent">
5 <TextView android:id="@+id/custom_spotoverview_tralala" android:text="@string/no_entrys" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/custom_spotoverview_tralala3" android:background="@drawable/wd_wsw" android:layout_width="wrap_content" android:layout_height="wrap_content" />
6 <ImageView android:id="@+id/custom_spotoverview_tralala4" android:background="@drawable/wd_n" android:layout_width="wrap_content" android:layout_height="wrap_content" />
7 </LinearLayout>
8</LinearLayout>


Mir geht es darum halt die Objecte vom Typ SpotConfigurationVO nutzen zu können um später entsprechend z.b ein ImageView mit einem Drawable zu versorgen.


Hat jemand eine Lösung dafür ?


PS: Die Codeformatierung wird mal wieder nach dem "Speichern" total verhunzt! Das Forum wird dadurch unbrauchbar!

— geändert am 09.07.2009, 11:43:13

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Antworten
Mac Systems
  • Forum-Beiträge: 1.727

09.07.2009, 11:54:39 via Website

Ich stelle gerade fest das Ich mal mehr in der API Doc hätte lesen sollen, aber ohne INet die letzten Tage ist das ein Problem gewesen.


Hier die Lösung:

1public View getView(int position, View convertView, ViewGroup parent) { final SpotConfigurationVO weather = spotList.get(position); final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View view = inflater.inflate(rowResID, null); view.setBackgroundColor(Color.BLUE);
2 return view; }


HTH,
Mac

Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV

Antworten
Gelöschter Account
  • Forum-Beiträge: 5.136

09.07.2009, 18:32:55 via Website

HI Mac,

fein das Du so rasch die Lösung hast finden können ;)

Ein schöner Ansatz ...

lg
Voss (aka Jörg)

lg Voss

Antworten