Frage

Gibt es eine Site, an der ich das Innenleben des Baseexpandablelistadapter finden kann? Ich habe die API gelesen und verstehe immer noch nicht, wie sie durch das gesamte Array geliefert wird, das geliefert wird, um die Ansicht zu gewährleisten. Ich habe Probleme mit meiner eigenen Implementierung. Ich kann keine ganze Liste erweiterbarer Listen erstellen, ohne die ExpanceListActivity zu verwenden, obwohl beide gleich sind. Es soll Strings aus der Datenbank abrufen und aus jedem ein explodableListView herausstellen und alle erstellten ExpansionsLeRisten in ein linearlayout in Main.xml hinzufügen. Was passiert, ist, dass nur die ExpanceListView für die erste Zeichenfolge angezeigt wird. Hier ist der Ausschnitt

Hauptklasse:

public class MainActivity extends Activity implements OnClickListener {
DBAdapter groupTable = new DBAdapter(this);
ExpandableListView groupLabel;
GroupAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

       groupTable.open();
    adapter = new GroupAdapter(groupTable.getAllGroups());
    retrieveExpandables(adapter);
       groupTable.close();
    Button addGroupButton = (Button)findViewById(R.id.addGroup);
    addGroupButton.setOnClickListener(this);
}

public void retrieveExpandables(GroupAdapter adapter) { 
    LinearLayout layout = (LinearLayout)findViewById(R.id.grouplist);
    LinearLayout groupLayout =    
             (LinearLayout)getLayoutInflater().inflate(R.layout.grouplistview, null);

    ExpandableListView groupExpandableList = 
             (ExpandableListView)groupLayout.findViewById(R.id.groupLabel);
    groupExpandableList.setAdapter(adapter);

    layout.addView(groupLayout);
}

BaseexpandablelistAdapter -Klasse:

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    if (convertView instanceof ViewGroup)
        return (ViewGroup) convertView;
    Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);
    ViewGroup item = (ViewGroup)inflater.inflate(R.layout.grouplisttext, null);
    TextView groupLabel = (TextView)item.findViewById(R.id.groupLabel);
    groupLabel.setText(groups[groupPosition].name);
    groupLabel.setVisibility(View.VISIBLE);
    Log.d("A1", "This part repeating");
    return item;
}

XML -Datei für die Textansicht, die der expandierbare Listentitel ist

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:id="@+id/groups"
          android:layout_height="wrap_content">

    <TextView android:id="@+id/groupLabel"
              android:textSize="24sp"
              android:text="asdf"
              android:textStyle="bold"
              android:layout_width="fill_parent"
              android:layout_weight="1"
              android:layout_height="40dip"
              android:layout_marginLeft="45dip"
              android:gravity="center_vertical" />

 </LinearLayout>

XML -Datei für die ExpaceableListView

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:id="@+id/groups"
          android:layout_height="wrap_content">

    <ExpandableListView android:id="@+id/groupLabel"
              android:textSize="24sp"
              android:textStyle="bold"
              android:layout_width="fill_parent"
              android:layout_weight="1"
              android:layout_height="40dip" />

 </LinearLayout>

Entschuldigung, wenn ich zu viel Code gepostet habe, habe ich versucht, so viel unnötige Informationen wie möglich zu entfernen.

War es hilfreich?

Lösung

Ich fand heraus, wo das Problem schief gelaufen ist. Anscheinend habe ich das Linearlayout und die Scrollview in der main.xml austauschten, und die Methode zur GetViewGroup -Klasse war falsch. Es ist jetzt alles gut

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top