Note that there are some explanatory texts on larger screens.

plurals
  1. POCustomlistview not inflating
    primarykey
    data
    text
    <p>I was trying to implement simple customlistview.What i tried to do is to inflate a text and a picture inside each list row in the listview.I got no output i.e. layout was not inflating..I got a blank screen.I used 2 Java class and 2 xml files.Below is my code..Please let me know where is my mistake and what should i correct?</p> <h2>CListView.java</h2> <pre><code>package com.example.customlistview; public class Clistview extends Activity { int p1[]={R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher}; String[] Shapes1={"circle","circle","circle","circle","circle"}; ListView lv; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_clistview); lv=(ListView)findViewById(R.id.listView1); CustomListViewAdapter clvadapter=new CustomListViewAdapter(Clistview.this,Shapes1,p1); lv.setAdapter(clvadapter); } } </code></pre> <h2>CustomListViewAdapter.java</h2> <pre><code>package com.example.customlistview; public class CustomListViewAdapter extends BaseAdapter { Context context; String shape1[]; int pic[]; public CustomListViewAdapter(Context c,String[] sh,int[] p) { this.context=c; this.shape1=sh; this.pic=p; } public int getCount() { // TODO Auto-generated method stub return 0; } public String getItem(int pos) { // TODO Auto-generated method stub return shape1[pos]; } public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } public View getView(int pos, View v, ViewGroup vg) { // TODO Auto-generated method stub View itemview=v; TextView tv1; ImageView im1; if(itemview==null) { LayoutInflater inflater=(LayoutInflater)((Activity)context).getLayoutInflater(); itemview=inflater.inflate(R.layout.clistview1,vg,false); } tv1=(TextView)itemview.findViewById(R.id.textView1); im1=(ImageView)itemview.findViewById(R.id.imageView1); tv1.setText(shape1[pos]); im1.setImageResource(pic[pos]); return itemview; } } </code></pre> <h2>activity_clistview.xml</h2> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Clistview" &gt; &lt;ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="16dp" &gt; &lt;/ListView&gt; &lt;/RelativeLayout&gt; </code></pre> <h2>clistview1.xml</h2> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="right" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload