1

I am unable to inflate a xml(layout containing QuickContactBadge) file using LayoutInflater, to use it inside ListView. It is not producing either compile/run time error or proper expected output. After I removed QuickContactBadge from XML Layout file, It gets inflated properly. How to solve this issue?

  1. Is it possible to inflate a XML layout file which have QuickContactBadge?
  2. If it is possible, What is the correct procedure to inflate a XML layout file which have QuickContactBadge, to use inside ListView?

Edit

message_item.xml

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


<QuickContactBadge
    android:id="@+id/quickContactBadge1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/lLayoutContentDisplayHolder"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvPerson"
        android:textIsSelectable="false"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/strPerson"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/tvMessage"
        android:textIsSelectable="false"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/strLastMessage" />

    <TextView
        android:id="@+id/tvTime"
        android:textIsSelectable="false"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/strLastMessageReceivedTime" />

</LinearLayout>

</LinearLayout>

Edit: Updated code And getView() method of ContactListAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    //return super.getView(position, convertView, parent);
    if(context != null){
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View linearLayout = inflater.inflate(R.layout.message_item, null);
        Contact contact = (Contact)getItem(position);
        TextView tvPerson = (TextView)linearLayout.findViewById(R.id.tvPerson);
        tvPerson.setText("Sample Text");
        Log.i("Test","Sample Text");
        return linearLayout;
    }else{
        return null;
    }
}

Console Output:

07-10 17:00:26.511: I/Test(3574): Sample Text
07-10 17:00:26.611: I/Test(3574): Sample Text
07-10 17:00:26.621: I/Test(3574): Sample Text
07-10 17:00:26.641: I/Test(3574): Sample Text
07-10 17:00:26.661: I/Test(3574): Sample Text
07-10 17:00:26.691: I/Test(3574): Sample Text
07-10 17:00:26.701: I/Test(3574): Sample Text

P.S: Am not setting values for all the widgets used in that layout. I expected the list with only person name but It is not producing any error while compiling and also while running. But it displays only empty screen.

1 Answers1

1

Your problem is in your getView function- it needs to return the linearLayout you inflated. I'm not sure what its returning- view isn't a local variable.

Also, you only want to inflate if convertView passed in is null- otherwise you want to set the data without inflating to reuse the view.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Oh sorry sorry, Now I got what mistake I have done. Its nothing but a Empty view. Thanks a lot. I will try this corrected code and post you shortly. Once again thank you very much. – Gowtham Shanmugaraj Jul 10 '13 at 03:42
  • Hi Sechan, I have updated the code as you said, But now I am facing another problem. Now inflated layout is displaying (but only one, even the list have 7 contact, I have updated the console output also). – Gowtham Shanmugaraj Jul 10 '13 at 11:48