由于某种原因,我无法查看包含在 row.xml 文件中的列表视图按钮。
这是我正在使用的 main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/friendsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
row.xml 如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="2dp">
<ImageView android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_marginRight="10dp"
android:contentDescription="@string/fbUserPic"/>
<TextView android:id="@+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:textStyle="normal"
android:textSize="12dp"
android:textColor="#FFFFFF"/>
<Button android:id="@+id/btnPost"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/fbbtnPost"
android:focusable="false"/>
</LinearLayout>
以下是我正在使用的自定义适配器中的 getView 覆盖
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
FriendRowHolder friendHolder = null;
if (row == null)
{
LayoutInflater inflater = ((Activity)objContext).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
friendHolder = new FriendRowHolder();
friendHolder.txtTitle = (TextView) row.findViewById(R.id.txtTitle);
friendHolder.imgIcon = (ImageView) row.findViewById(R.id.imgIcon);
friendHolder.btnPost = (Button) row.findViewById(R.id.btnPost);
row.setTag(friendHolder);
}
else
{
friendHolder = (FriendRowHolder)row.getTag();
}
Friend objFriend = lstFriends.get(position);
friendHolder.txtTitle.setText(objFriend.GetName());
friendHolder.imgIcon.setImageBitmap(loadBitmap(objFriend.GetPictureURL()));
friendHolder.btnPost.setText("Hi");
return row;
}