B
Binbose
Ambitioniertes Mitglied
- 0
Hallo Leute,
ich sitze jetzt schon seit 2 Tagen daran meine ListView mit einem eigenen Layout mit einem Custim Adapter zu füllen, bekomme aber immer eine NullPointException und finde meinen Fehler einfach nicht.
Ich mache das mit den Custom Adaptern zum ersten mal, also seid bitte nicht zu hart, falls es ein einfacher Dumbatz Fehler ist^^
Hoffentlich könnt ihr mir helfen, hier mein Layout für die Listeneinträge:
und hier der Code für die Activite mit Custom Adapter:
Danke schonmal im Vorraus,
mfg Binbose
ich sitze jetzt schon seit 2 Tagen daran meine ListView mit einem eigenen Layout mit einem Custim Adapter zu füllen, bekomme aber immer eine NullPointException und finde meinen Fehler einfach nicht.
Ich mache das mit den Custom Adaptern zum ersten mal, also seid bitte nicht zu hart, falls es ein einfacher Dumbatz Fehler ist^^
Hoffentlich könnt ihr mir helfen, hier mein Layout für die Listeneinträge:
HTML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="CheckBox" />
</RelativeLayout>
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:text="Text View"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
Code:
public class MeineActivity extends ListActivity{
private MeineDataSource datasource;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mein_layout);
datasource = new MeineDataSource(this);
datasource.open(); //Datenbankverbindung erstellen
ArrayList<MeinDataModel> values = new ArrayList<MeinDataModel>();
values = datasource.getAllEntries(); //Datenbankeinträge werden in Objekte der Klasse MeinDataModel gepackt
MeinAdapter adapter = new MeinAdapter(this,
values);
setListAdapter(adapter);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
protected void onResume() {
datasource.open();
super.onResume();
}
protected void onPause() {
datasource.close();
super.onPause();
}
public void onClickSpeichern(final View view){
//Datenbank aktualisieren
final Intent i = new Intent(this, MainActivity.class);
startActivity(i);
}
//Eigener Adapter
public class MeinAdapter extends ArrayAdapter {
private final Context context;
private final ArrayList<MeinDataModel> values;
public MeinAdapter(Context context, ArrayList<MeinDataModel> values){
super(context, R.layout.mein_eintrag_layout, values);
this.values = values;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View listenEintrag = inflater.inflate(R.layout.mein_eintrag_layout, parent, false);
CheckBox checkbox = (CheckBox) findViewById(R.id.checkBox1);
checkbox.setText(values.get(position).getName());
TextView textview = (TextView) findViewById(R.id.tv1);
textview.setText(values.get(position).getNummer());
return listenEintrag;
}
}
}
mfg Binbose