I am trying to display a list for this I used one class Ios.java
public class Ios extends Activity implements OnItemClickListener,OnClickListener
{
list=(ListView) findViewById(R.id.list);
list.setOnItemClickListener(this);
String DATA[] = {"io1","io2","io3","io4","io5"};
IosListAdapter obj = new IosListAdapter(this.getApplicationContext()
,R.layout.row, DATA);
list.setAdapter(obj);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}}
My custom adapter is below:
public IosListAdapter(Context con, int rid,String[] dATA) {
// TODO Auto-generated constructor stub
this.con = con;
this.DATA = dATA;
this.rid = rid;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater loi = LayoutInflater.from(con);
View v = loi.inflate(rid, parent, false);
ImageView iv= (ImageView) v.findViewById(R.id.t1);
TextView tv1 = (TextView) v.findViewById(R.id.t4);
iv.setBackgroundResource(arrow);
tv1.setText(DATA[position]);
return v;
}}
and demolist.xml::
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#f1eff0">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:stretchColumns="1" android:gravity="center_vertical"
android:background="@drawable/toptab" android:id="@+id/tb1">
<TableRow>
<Button android:id="@+id/btnback" android:background="@color/hover_bckbtn"
android:text="Back" android:textColor="#ffffff" android:textSize="14sp"
android:textStyle="normal" android:typeface="normal"
android:layout_marginLeft="5dp" />
<TextView android:id="@+id/tvnormalcallreg" android:text="Call Registration"
android:textColor="#ffffff" android:textSize="18sp"
android:layout_gravity="center" android:textStyle="normal"
android:typeface="normal" />
<Button android:id="@+id/btnregister" android:textColor="#ffffff"
android:background="@color/hover_button" android:text="Register"
android:textSize="14sp" android:textStyle="normal" android:typeface="normal"
android:layout_marginRight="5dp" />
</TableRow>
</TableLayout>
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:stretchColumns="0"
android:layout_marginRight="30dp">
<TableRow android:gravity="center_vertical"
android:layout_width="fill_parent">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/top" android:layout_height="wrap_content"
android:textStyle="bold" android:layout_width="wrap_content"
android:singleLine="true" android:textColor="#ffffff"
android:typeface="normal" />
<TextView android:id="@+id/address" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="10sp"
android:textColor="#ffffff" android:typeface="normal"
android:layout_marginTop="-2dp" />
<TextView android:id="@+id/tvdept" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="10sp"
android:textColor="#ffffff" android:typeface="normal"
android:layout_marginTop="-2dp" />
</LinearLayout>
</TableRow>
</TableLayout>
<ListView android:id="@+id/list"
android:layout_below="@+id/toptbl"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="fill_parent"
android:cacheColorHint="#00000000"
android:fadingEdge="none"
android:layout_marginBottom="50dp"/>
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:id="@+id/bottom">
<TableRow android:background="@drawable/toptab"
android:gravity="center">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/logobottom" />
</TableRow>
</TableLayout>
</RelativeLayout>
Its running fine only problem I am facing is that list is not displaying and when I debug it I found that getView method of adapter is never called.
Your
getCountmethod should return the number of rows that you have, based on the data you provide to the adapter. Something like this: