我有ListView
并使用BaseAdapter
填充它。
虽然getCount()
方法返回4,但未调用getView
方法,因为Log.i("Inside Get View"," ");
未显示在日志中:
我试图在SMS(Inbox)
ListView
public class AllSMSListAdapter extends BaseAdapter
{
private Context mContext;
ArrayList<String> SMSContactList;
Cursor cursor;
public AllSMSListAdapter(Context context,Cursor cur)
{
super();
SMSContactList=new ArrayList<String>();
mContext=context;
cursor=cur;
}
public int getCount()
{
{
Log.i("Number of Records returned:"+cursor.getCount()," In get count ");
return cursor.getCount();
}
}
public View getView(int position, View view, ViewGroup parent)
{
Log.i("Inside Get View"," ");
if (view == null)
{
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.each_sms, null);
}
cursor.moveToPosition(position);
String senderNumber=cursor.getString(cursor.getColumnIndex("address"));
String smsBody=cursor.getString(cursor.getColumnIndex("body"));
SMSContactList.add(senderNumber);
TextView textViewConatctNumber = (TextView)view.findViewById(R.id.textViewSMSSenderAll);
TextView textViewSMSBody=(TextView)view.findViewById(R.id.textViewSMSBodyAll);
Log.i(senderNumber," "+smsBody);
textViewConatctNumber.setText(senderNumber);
textViewSMSBody.setText(smsBody);
return view;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
ListView XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listAllSMSes"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="0.1dp"
android:divider="#000000"
>
</ListView>
</LinearLayout>
ListView的每一行:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewSMSSenderAll"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#CC0000"
android:text="Sender Number"
android:layout_marginLeft="5dp"
android:textSize="20dp"/>
<TextView
android:id="@+id/textViewSMSBodyAll"
android:textColor="#006600"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Message"
android:layout_marginLeft="1dp"
android:layout_marginBottom="7dp"
android:textSize="17dp"/>
</LinearLayout>