Android ListView und Checkbox

mysterix

Mitglied
Hi Leute,

ich bin nun endlich von nem Scrollview auf ne ListView umgestiegen weil mir das hier mal empfohlen wurde. Ich habe eine Liste mit TableRows. In diesem TableRow liegen mehrere textboxen, ein image und eine Checkbox. ich habe also pro Eintrag eine Checkbox. Nun habe ich das Problem, dass wenn ich durch meine z.Z. 90 Einträge scrolle und einen Eintrag anhake, dass dann jeder 3. Eintrag nen Haken hat. Und wenn ich nen anderen eintrag anhake dann hat auch jeder 3. Eintrag nen Hacken. Sprich, wenn ich die aller ersten 3 Einträge anhake, sind plötzlich ALLE Einträge angehakt... Hat jemand ne Idee woran das liegen könnte? Kennt das jemand?
 

mysterix

Mitglied
Hallo,

ohne Deinen Quellcode kann man dazu eher wenig sagen.

Gruß
wohl richtig, sorry. Also:

Galerie.java
Java:
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	

			super.onCreate(savedInstanceState);
			setContentView(R.layout.galerie);
			


			filme = new ArrayList<Film>();
			DatensaetzeLaden();
			
			Collections.sort(filme, new SortierNachName());
			
			ListAdapter boxAdapter = new FilmeAdapter(this, filme);
	         
	        // Get reference to ListView holder
	        ListView lv = (ListView) this.findViewById(R.id.galerieeintraege);
	         
	        // Set the ListView adapter
	        lv.setAdapter(boxAdapter);
			


		
	}

ListViewAdapter.java
Java:
package com.example.barcodescanningapp;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
 
public class ListViewAdapter extends ArrayAdapter<Film> {
    private static final String tag = "ListViewAdapter";
    private static final String ASSETS_DIR = "images/";
    private Context context;
    private ImageView filmIcon;
    private TextView filmName;
    private TextView filmBeschreibung;
    private TextView filmGenre;
    private RatingBar filmBewertung;
    private List<Film> filme = new ArrayList<Film>();
	File root = android.os.Environment.getExternalStorageDirectory();
 
    public ListViewAdapter(Context context, int textViewResourceId,
            List<Film> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
        this.filme = objects;
    }
 
    public int getCount() {
        return this.filme.size();
    }
 
    public Film getItem(int index) {
        return this.filme.get(index);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        if (row == null) {
            // ROW INFLATION
            Log.d(tag, "Starting XML Row Inflation ... ");
            LayoutInflater inflater = (LayoutInflater) this.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.eintrag, parent, false);
            Log.d(tag, "Successfully completed XML Row Inflation!");
        }
 
        // Get item
        Film film = getItem(position);

        // Get reference to ImageView 
        filmIcon = (ImageView) row.findViewById(R.id.imgBild);
        filmName = (TextView) row.findViewById(R.id.txtName);
        filmBeschreibung = (TextView) row.findViewById(R.id.txtBeschreibung);
        filmGenre = (TextView) row.findViewById(R.id.txtGenre);
        filmBewertung = (RatingBar) row.findViewById(R.id.rdbBewertung);

        filmName.setText(film.getName());
        filmBeschreibung.setText(film.getBeschreibung());
        filmGenre.setText(film.getGenre());
        filmBewertung.setRating(film.getBewertung());
        filmBewertung.setEnabled(false);
        if(film.getStrichcode() != null)
        {
	        File anzeigebild = new  File(root.getAbsolutePath() + "/mnt/sdcard/FilmBilder/" + film.getStrichcode() + ".jpg"); 
		    if(anzeigebild.exists())
		    	filmIcon.setImageBitmap(BitmapFactory.decodeFile(anzeigebild.getAbsolutePath()));
        }

         
        return row;
    }
}

und die layouts.

eintrag.xml
[XML]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:eek:rientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<CheckBox
android:id="@+id/ausgewaehlt"
android:layout_width="wrap_content"
android:layout_height="match_parent" />

<ImageView
android:id="@+id/imgBild"
android:layout_width="208dp"
android:layout_height="208dp"
android:clickable="true"
android:src="@drawable/ic_launcher"
android:tag="Bild" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:eek:rientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titel" />

<TextView
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="Name"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beschreibung" />

<TextView
android:id="@+id/txtBeschreibung"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="Beschreibung"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Genre" />

<TextView
android:id="@+id/txtGenre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="Genre"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />

<RatingBar
android:id="@+id/rdbBewertung"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="Bewertung" />
</LinearLayout>

</LinearLayout>

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.70"
android:gravity="center"
android:text="................................................................................"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

[/XML]

Galerie.xml
[XML]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@+id/galerieeintraege"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>[/XML]
 
Zuletzt bearbeitet:

dzim

Top Contributor
Nach einiger Zeit mal eine kleine Antwort. Rein vom code her kann ich das Problem nicht sehen, aber ich vermute, das du hier mit dem Fokus herum spielen musst. Vor einiger Zeit gab es hier im forum schon mal ein ähnliches Problem. Ich glaube, der ListView schluckt die events. Ich rate dir mal danach zu suchen.
 

mysterix

Mitglied
Nach einiger Zeit mal eine kleine Antwort. Rein vom code her kann ich das Problem nicht sehen, aber ich vermute, das du hier mit dem Fokus herum spielen musst. Vor einiger Zeit gab es hier im forum schon mal ein ähnliches Problem. Ich glaube, der ListView schluckt die events. Ich rate dir mal danach zu suchen.

Hiho, kannst du mir sagen wie du das meinst "mit dem Fokus rumspielen"? 'Hast du dafür ein Beispiel?
 

dzim

Top Contributor
Nein. hab den code von Arbeit nicht hier. Aber hier im forum gab es kürzlich etwas mit EditText... War es @kurztipp? Vielleicht findest du da was!
 

kurztipp

Aktives Mitglied
Hallo,

ohne mir jetzt den Code genau angeschaut zu haben etwas generelles: Was dzim meint, ist, dass es bei der Verwendung von ListView zu Problemen kommen kann, wenn sich innerhalb der ListView andere Views befinden, die Fokus erhalten können. Das sind z.B. EditText, CheckBox, RadioButton oder im Prinzip jede View, die clickable="true" ist.
Das liegt daran, dass ListView standardmäßig onListItemClick und onListItemLongClick listener bereitstellt. Kann ein anderes Elemente innerhalb einer ListView angeklickt werden/den Fokus erhalten, dann ergibt sich folgendes Problem: Woher soll ListView wissen, ob jetzt beispielsweise ein Haken in der CheckBox gesetzt werden soll oder onListItem(Long)Click (die sich beide auf die ganze ListView Reihe beziehen) bedient werden soll?
Daher die Anregung, mit dem Fokus zu experimentieren.

Ein paar Dinge, die mir beim überfliegen des Codes aufgefallen sind:
a) Deine Activity sollte ListActivity erweitern
Code:
extends ListActivity
, dann kannst Du in onCreate
Code:
setListAdapter(mAdapter);
benutzen und musst nicht über findViewById gehen (was evtl auch unsauber ist?).
b) In onCreate setzt Du FilmeAdapter als Adapter, postest aber hier den QuellCode für ListViewAdapter, der laut Quellcode nicht benutzt wird?

Veränderst/setzt Du irgendwo eigene Listener für Deine Checkboxen?

Gruß
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
J ListView Item individuell einfärben Android & Cross-Platform Mobile Apps 17
I Android ListView, Werte aktualisieren ohne die Liste komplett neu zu laden Android & Cross-Platform Mobile Apps 5
W ListView OnItemClicklistener setzen mit Ausgabe Android & Cross-Platform Mobile Apps 35
K Null-Pointer-Exception in ListView - wird über Datenbank gefüllt Android & Cross-Platform Mobile Apps 1
I Android ListView (Custom) soll auf Hardwaretasten nicht reagieren. Android & Cross-Platform Mobile Apps 10
W ListView und Arrays... Android & Cross-Platform Mobile Apps 68
W Android Wieso kann ich keine ListView mehr zum Layout hinzufügen? Android & Cross-Platform Mobile Apps 1
W Android Kann keine ListView mehr in der MainActivtiy anzeigen, obwohl noch sehr viel Platz frei ist Android & Cross-Platform Mobile Apps 1
L ListView aktuallisiert sich nicht Android & Cross-Platform Mobile Apps 15
N Probleme mit custom dynamic ListView Android & Cross-Platform Mobile Apps 15
L Android ListView kollabiert in Scrollview Android & Cross-Platform Mobile Apps 9
A ImageButton in ListView Item bei klick ändern Android & Cross-Platform Mobile Apps 3
J Android Suche in einer ListView Android & Cross-Platform Mobile Apps 3
H Android ArrayList <-> ArrayAdapter <-> ListView Android & Cross-Platform Mobile Apps 10
L Android ListView swipe zum löschen Android & Cross-Platform Mobile Apps 1
B Android ListView set custom check Image and delete Android & Cross-Platform Mobile Apps 0
M Android ListView wird nicht dargestellt Android & Cross-Platform Mobile Apps 2
Maresuke Android Android ListView Textfarbe und Texthintergrund ändern? Android & Cross-Platform Mobile Apps 5
A Android Problem mit ListView und OnItemClickListener.. Android & Cross-Platform Mobile Apps 10
S Listview Einträge aus "xml" Datei Android & Cross-Platform Mobile Apps 1
S Android Studio MySql Daten in Listview mit sub Item Android & Cross-Platform Mobile Apps 11
S Textdatei in ListView einlesen Tutorial gesucht!? Android & Cross-Platform Mobile Apps 3
kaoZ Tutorial .xml Layouting für z.B ListView elemente Android & Cross-Platform Mobile Apps 7
L TableRows in ListView darstellen Android & Cross-Platform Mobile Apps 2
M ListView mit ListAdapter füllen Android & Cross-Platform Mobile Apps 5
U Android ListView Frage Android & Cross-Platform Mobile Apps 6
L Android SearchBox für Custom Listview Android & Cross-Platform Mobile Apps 5
H Android ListView Images aus dem Internet via Thread Android & Cross-Platform Mobile Apps 3
T Android: ListView-Adapter: Adapter wird ständig aufgerufen Android & Cross-Platform Mobile Apps 2
H Android SAX|ListView NullPointerException Android & Cross-Platform Mobile Apps 2
A Probleme mit ListView / ArrayAdapter Android & Cross-Platform Mobile Apps 3
S Android CheckBox Status von anderer Klasse aus ändern Android & Cross-Platform Mobile Apps 4

Ähnliche Java Themen

Neue Themen


Oben