Wijden
Wijden

Reputation: 511

Android - ListView showing one single row only

I'm facing a problem with ListView which show only one single row in the ListView. I think the problem is in the layout row xml but I can't figure out where the problem is. Thank you for helping I would apreciate it.

This is my row.xml

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

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/imageTypeWorkitem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:paddingTop="10dp"
                android:src="@drawable/bugicon" />

            <TextView
                android:id="@+id/typeWorkitem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:paddingTop="10dp"
                android:textSize="14sp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/imagePriority"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:paddingTop="10dp"
                android:src="@drawable/priorityhigh" />

            <TextView
                android:id="@+id/priority"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:paddingTop="10dp"
                android:textSize="14sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/key"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:paddingTop="10dp"
                android:textSize="14sp"
                android:textStyle="bold" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/imageStatus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:paddingTop="10dp"
                android:src="@drawable/statusopen" />

            <TextView
                android:id="@+id/status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/priority"
                android:layout_marginLeft="10dp"
                android:paddingTop="10dp"
                android:textSize="14sp"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

This is My adapter :

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.client.alm.model.WorkItem;
import com.client.alm.model.WorkItemContainer;

public class WorkItemAdapter extends ArrayAdapter<WorkItem> {

    private WorkItemContainer container;
    private Context context;
    int layoutResourceId;

    public WorkItemAdapter(Context context, int layoutResourceId,
            WorkItemContainer container) {
        super(context, layoutResourceId, container.getWorkitems());
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.container = container;
    }

    static class ViewHolder {
        ImageView imageType;
        TextView type;
        TextView priority;
        ImageView imagePriority;
        TextView key;
        ImageView imageStatus;
        TextView status;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new ViewHolder();
            holder.imageType = (ImageView) row
                    .findViewById(R.id.imageTypeWorkitem);
            holder.type = (TextView) row.findViewById(R.id.typeWorkitem);
            holder.imagePriority = (ImageView) row
                    .findViewById(R.id.imagePriority);
            holder.priority=(TextView) row.findViewById(R.id.priority);
            holder.key = (TextView) row.findViewById(R.id.key);
            holder.imageStatus = (ImageView) row.findViewById(R.id.imageStatus);
            holder.status = (TextView) row.findViewById(R.id.status);

            row.setTag(holder);
        } else {
            holder = (ViewHolder) row.getTag();
        }

        WorkItem workitem = container.getWorkitems().get(position);
        holder.type.setText(workitem.getType());
        // holder.imageType.setImageResource(workitem.getIcon());
        holder.priority.setText(workitem.getPriority());
        holder.key.setText(workitem.getKey());
        holder.status.setText(workitem.getStatus());

        return row;
    }

}

And this the code where I am loading the list :

WorkItemContainer container = gson.fromJson(resultat,
                    WorkItemContainer.class);

            /**
             * Updating parsed JSON data into ListView
             * */
            WorkItemAdapter adaptateur = new WorkItemAdapter(
                    WorkItemActivity.this, R.layout.ligne_workitem, container);
            setListAdapter(adaptateur);

Upvotes: 1

Views: 8870

Answers (2)

Sagar Waghmare
Sagar Waghmare

Reputation: 4742

I think the problem is your listview height.

Make the listview height as match_parent

Upvotes: 0

Raman Ghai
Raman Ghai

Reputation: 186

  1. You may try using RelativeLayout to design your single row.
  2. Get rid of the Outermost LinearLayout. You are using so many linearlayouts to design a simple row. This might have effect on the performance of UI.

Rest , I cannot say much without looking at the code where ListView is being instantiated and the Adapter is set. Best of luck.

Upvotes: 1

Related Questions