0

Hi i have a slight problem when using an ArrayAdapter, what is happening is that not all of each rows data is being displaying in each row but for other rows its fine and displaying all the data, i hope that makes sense. example list result as displayed in app.

20238 Christian Neza
20394 Christian Kezama
23554 Christian

In the above list displayed in the app the only one showing all of the row text is the middle one 20394.

In the below code for the ClientListAdapter i have put a Log if the record = 20238, the output from that log shows that the actual row data is

20238 Christian Neza Bizimana

and also 23554 has cut of the last part of the text to be displayed, very odd saying 50% of the list is displaying correct.

public class ClientListAdapter extends ArrayAdapter<ClientListVO> {

    private ArrayList<ClientListVO> items;

    public ClientListAdapter(Context context, int textViewResourceId, ArrayList<ClientListVO> items) {
            super(context, textViewResourceId, items);
            this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;

            if (v == null) {
                LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.renderer_clientlist, null);
            }
            ClientListVO o = items.get(position);

            if (o != null) {
                    if(o._id == 20238)
                        Log.i("ClientListAdapter", o.toString());
                    TextView tt = (TextView) v.findViewById(R.id.toptext);
                    if (tt != null)
                        tt.setText(o.toString());
            }

            return v;
    }
}

The R.layout.renderer_clientlist

<?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="?android:attr/listPreferredItemHeight"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/toptext"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:gravity="center_vertical" />

</LinearLayout>

The final piece of code i think you need is the actual ListView in the Activity where the data is being displayed.

 <ListView
    android:id="@+id/listview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" /> 

Please can anyone shed any light on what im doing wrong, Thanks in Advance I'm on a really tight deadline for this.

4 Answers 4

2

It's probably because of this statement android:layout_width="fill_parent". This would mean that text which is the same size of the screen's width can be displayed but anything longer would be hacked off.

Try using android:layout_width="wrap_content"

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for this it now displays perfectly. I always like simple solutions
1

What I assume is your text is too long for the view to be displayed. The view can manage the integer value with two more words (like: "20394 Christian Kezama").But after that remaining text is deprecated. You can reduce the size of your text in Text View to fit all the texts. This is one of the many possible solutions.

Comments

0
 keep this  out of the condition      
       LayoutInflater vi =(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

and check you items if all data is coming or not

2 Comments

Sorry anddevmanu but what your suggesting isn't making sense to me, if i dont include it then vi will be null and nothing will be returned, also i have checked the data with the log output as i mentioned in my post. please explain what you meant by "keep this out of the condition"
dont remove that just write these in out of your condition
0

can you check whether it is displaying full name if you remove android:layout_weight="1" from TextView.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.