Created
March 7, 2018 09:52
-
-
Save bluemyria/78bca3ae3459c94308cb476c688120f6 to your computer and use it in GitHub Desktop.
Android - 011 - LayoutInflater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////////////////////////// | |
// MyListAdapter implements ListAdapter | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
class MyListAdapter implements ListAdapter { | |
private ArrayList<Datensatz> eintraege; | |
private Context context; | |
public MyListAdapter(Context context) { | |
this.context = context; | |
// Datensatz siehe unten | |
eintraege = new ArrayList<Datensatz>(); | |
for (int i = 0; i<100; i++) { | |
Datensatz d = new Datensatz("Index " + i, "Info " + i); | |
eintraege.add(d); | |
} | |
} | |
....... | |
@Override | |
public View getView(int i, View view, ViewGroup viewGroup) { | |
/* | |
* Listitem: ist ein LinearLayout mit anderen Views drin, in einer separaten layout Datei | |
* Diese Layout Datei (listitem.xml) wird geladen mit einer Klasse die das Layout "aufpustet" | |
* damit die Views darin gefuellt werden | |
* Die Klasse ist der "InflaterService" (kommt über das System) | |
*/ | |
LayoutInflater li = (LayoutInflater) context.getSystemService(Context | |
.LAYOUT_INFLATER_SERVICE); | |
// das aufzupustende Element ist eine View, ViewGroup ist null in unserem Fall | |
View v = li.inflate(R.layout.listitem, null); | |
TextView tvOben = v.findViewById(R.id.tvOben); | |
TextView tvUnten = v.findViewById(R.id.tvUnten); | |
Datensatz satz = (Datensatz) getItem(i); | |
tvOben.setText(satz.info1); | |
tvUnten.setText(satz.info2); | |
return v; | |
} | |
....... | |
} | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
// in Datensatz | |
////////////////////////////////////////////////////////////////////////////////////////////// | |
public class Datensatz { | |
String info1, info2; | |
public Datensatz (String info1, String info2) { | |
this.info1 = info1; | |
this.info2 = info2; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment