hallo zusammen,
ich versuchs jetzt mal mit etwas mehr Quellcode
ArrayList<adresse> ist eine ArrayList der Klasse adresse
kann ich der View in der Main einen Index hinzufügen, oder geht das in der ListActivity nicht.
Wenn nein, wie kann ich dann einer ListView die Klasse Adresse übergeben, ohne alles auseinandernehmen zu müssen?
Ich danke euch
Java
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class ItemAdapteradresse extends ArrayAdapter<adresse> {
// declaring our ArrayList of items
private ArrayList<adresse> objects;
/* here we must override the constructor for ArrayAdapter
* the only variable we care about now is ArrayList<Item> objects,
* because it is the list of objects we want to display.
*/
public ItemAdapteradresse(Context context, int textViewResourceId, ArrayList<adresse> objects) {
super(context, textViewResourceId, objects);
this.objects = objects;
}
/*
* we are overriding the getView method here - this is what defines how each
* list item will look.
*/
public View getView(int position, View convertView, ViewGroup parent){
// assign the view we are converting to a local variable
View v = convertView;
// first check to see if the view is null. if so, we have to inflate it.
// to inflate it basically means to render, or show, the view.
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.adresselist_item2, null);
}
/*
* Recall that the variable position is sent in as an argument to this method.
* The variable simply refers to the position of the current object in the list. (The ArrayAdapter
* iterates through the list we sent it)
*
* Therefore, i refers to the current Item object.
*/
Adresse adresse = objects.get(position);
if (adresse != null) {
// This is how you obtain a reference to the TextViews.
// These TextViews are created in the XML files we defined.
// TextView tt = (TextView) v.findViewById(R.id.text123);
TextView tvadresseD = (TextView) v.findViewById(R.id.gaststaette);
TextView tvplzOrtD = (TextView) v.findViewById(R.id.plzort);
TextView tvstrasseNrD = (TextView) v.findViewById(R.id.strassenr);
if (tvadresseD != null){
tvadresseD.setText(adresse.getFirma());
}
if (tvplzOrtD != null){
tvplzOrtD.setText(adresse.getPLZ() + " " + adresse.getOrt());
}
if (tvstrasseNrD != null){
tvstrasseNrD.setText(adresse.getStrasse() + " " + adresse.getNr());
}
}
// the view must be returned to our activity
return v;
}
}
// in der Main.java (ListActivity)
m_parts.addAll(dbhandler.getAllAdressen());
m_adapter = new ItemAdapterAdresse(pMain.this, R.layout.adresslist_item1, m_parts);
// display the list.
setListAdapter( m_adapter);
Alles anzeigen