Frage

My problem is, that I have an activity with one big TextView and one ExpandableListView underneath the TextView. Unfortunately the text of the TextView is too long, so I can't see the details when I expand the ExpandableListView.

So my question is, how can I use CWAC-Merge in my Code, to get one big scrollable Activity.

I would like to have, that everything in the activity_contact.xml from scrollView1 to the bottom is scrollable! I already copied the necessary libs (merge-1.0.1.jar and sacklist-1.0.0.jar) to my Project, but I don't know how to apply the MergeAdapter. I would really appreciate, if someone could tell me where and how I have to use the MergeAdapter!

This is my activity_contact.xml:

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

    <include layout="@layout/titlebar" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_marginTop="0dp"
        android:layout_weight="1"
        android:fillViewport="true" >

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

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/contact"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:paddingLeft="5dp"
                    android:paddingRight="5dp"
                    android:text="@string/contact"
                    android:textSize="@dimen/textSize" />
            </TableRow>


            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <ExpandableListView
                    android:id="@+id/listView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp" >
                </ExpandableListView>
            </TableRow>
        </TableLayout>
    </ScrollView>
</LinearLayout>

This is my Contact.java class:

public class Contact extends Activity {

    private SparseArray<Group> groups = new SparseArray<Group>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact);
        ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
        createData();
        ExpandableListAdapter adapter = new ExpandableListAdapter(this, groups,
                false, null);
        listView.setAdapter(adapter);
    }

    private void createData() {
        Group group1 = new Group(getString(R.string.stringGroup));
        group1.children.add(getString(R.string.stringGroup2));
        groups.append(0, group1);
    }
}

This is my ExpandableListAdapter.java

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private final SparseArray<Group> groups;
    private LayoutInflater inflater;
    private Activity activity;
    private boolean setOnClickListener;
    private Class<?> onClickClass;

    public ExpandableListAdapter(Activity act, SparseArray<Group> groups,
            boolean setOnClickListener, Class<?> onClickListenerClass) {
        activity = act;
        this.groups = groups;
        inflater = act.getLayoutInflater();
        this.setOnClickListener = setOnClickListener;
        this.onClickClass = onClickListenerClass;

    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return groups.get(groupPosition).children.get(childPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        final String children = (String) getChild(groupPosition, childPosition);
        TextView text = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listrow_details, null);
        }

        text = (TextView) convertView.findViewById(R.id.copyrightTextView);
        text.setText(Html.fromHtml(children));


        if (setOnClickListener) {
            convertView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(activity, onClickClass);
                    intent.putExtra("name", children);
                    activity.startActivity(intent);
                }
            });
        }
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return groups.get(groupPosition).children.size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return groups.size();
    }

    @Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listrow_group, null);
        }
        Group group = (Group) getGroup(groupPosition);
        ((CheckedTextView) convertView).setText(group.string);
        ((CheckedTextView) convertView).setChecked(isExpanded);
        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }
}

The listrow_details.xml:

<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="50dp"
    android:clickable="true"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/copyrightTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawablePadding="15dp"
        android:gravity="center_vertical"
        android:linksClickable="true"
        android:padding="10dp"
        android:textStyle="bold" >
    </TextView>

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@android:color/black" />

</LinearLayout>
War es hilfreich?

Lösung

MergeAdapter is a ListAdapter, not an ExpandableListAdapter. You cannot use MergeAdapter to solve your problem. You are welcome to read through the source code to MergeAdapter and attempt to figure out if there is a way to create a MergeExpandableListAdapter or something like that.

Or, come up with a UI that does not have a long TextView after the ExpandableListView.

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