我正在开发Android应用程序,我想修复列表底部的按钮,所以如果刷新列表并且更多项目添加到列表中,那么按钮应该仍然是最后一个。
我使用了以下代码,但问题是它显示的是此图像的按钮。
<?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="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="@drawable/newlistselector"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="@drawable/newlistselector"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical"
android:orientation="horizontal" >
<com.ziqitza.views.CircularImageView
android:id="@+id/imgNotificationProfile"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="3dp"
android:padding="5dp"
android:scaleType="fitXY"
android:src="@drawable/profile_" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgSearchContact"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/ll_indicator"
android:src="@drawable/arrowright" />
<LinearLayout
android:id="@+id/ll_indicator"
android:layout_width="4dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/roundcorner_topright_downright"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="@+id/txtNotificationDesc"
android:layout_width="210dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:maxLines="2"
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000"
android:textSize="12sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<TextView
android:id="@+id/txtDateTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000"
android:textSize="9sp" />
<TextView
android:id="@+id/txtStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="9sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/imgSearchContact"
android:layout_marginRight="10dp"
android:gravity="center_vertical|right"
android:orientation="horizontal" >
<TextView
android:id="@+id/txtNotificationTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|right"
android:text="time"
android:textColor="#000"
android:textSize="8sp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
适配器和活页夹代码:
private AdapterDataBinder<ParseObject> mNotificationsBinder = new AdapterDataBinder<ParseObject>() {
@Override
public void bind(ParseObject data, View view, int position) {
if (isLoadingFirstTime) {
mHolder.mTxtDesciption = (TextView) view.findViewById(R.id.txtNotificationDesc);
mHolder.mTxtTime = (TextView) view.findViewById(R.id.txtNotificationTime);
mHolder.mImageProfile = (CircularImageView) view.findViewById(R.id.imgNotificationProfile);
mHolder.mll_State = (LinearLayout) view.findViewById(R.id.ll_indicator);
mHolder.mTxtDesciption.setText(data.getString("description"));
mHolder.txtStatus = (TextView) view.findViewById(R.id.txtStatus);
// mHolder.btnRequest = (Button) view.findViewById(R.id.button1);
mHolder.txtStatus.setVisibility(View.VISIBLE);
if (!data.getString("type").equals("TrustedNetwork")) {
showStatus(data);
} else
mHolder.txtStatus.setVisibility(View.GONE);
mHolder.mTxtTime.setText(mSDF.format(data.getCreatedAt()));
try {
if (data.getBoolean("seen")) {
mHolder.mll_State.setVisibility(View.INVISIBLE);
} else
mHolder.mll_State.setVisibility(View.VISIBLE);
ParseFile userimage = data.getParseObject("sender").getParseFile("profileImage");
if (userimage == null) {
Utils.loadProfileImage(NotificationsActivity.this, null, mHolder.mImageProfile);
} else
Utils.loadProfileImage(NotificationsActivity.this, null, mHolder.mImageProfile);
Picasso.with(view.getContext()).load(userimage.getUrl()).into(mHolder.mImageProfile);
} catch (Exception ex) {
ex.printStackTrace();
}
view.setTag(mHolder);
}else{
mHolder = (ViewHolder) view.getTag();
}
}
@Override
public void bind(ParseObject data, View view) {
}
};
持有人类别:
ViewHolder mHolder = new ViewHolder();
static class ViewHolder{
private TextView mTxtDesciption, mTxtTime;
private CircularImageView mImageProfile;
Button btn;// = (Button) findView(R.id.refreshBtn);
private LinearLayout mll_State;
TextView txtStatus;
Button btnRequest;
}
答案 0 :(得分:3)
如果您想在列表项的底部放置按钮,则可以使用addFooterView()
的{{1}}方法。例如,这将适用于列表页脚中添加的一个按钮。
ListView
这会将包含您在图片中提到的3个按钮的视图放在Button btn = new Button(this);
btn.setText("Done");
ListView lst = (ListView) findViewById(R.id.yourlist);
lst.addFooterView(btn);
// * your view containing the 3 buttons *//
的最后一项之后。
答案 1 :(得分:1)
继续发表评论..
count
解决方法
BaseAdapter
来充气ListView
更新getCount()
函数以发回增加的长度。
@Override
public int getCount() {
return data.length + 1;
}
现在,更新getView()
方法以根据位置对不同的视图进行充气。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(position != getCount() - 1)
convertView= layoutInflater.inflate(R.layout.item, null);
else
convertView= layoutInflater.inflate(R.layout.button, null);
return convertView;
}
ViewHolder
模式添加到此代码中。要使用AdapterDataBinder
,我不知道如何决定最大数量,所以你自己必须在getCount()
中查找调整,但代码是从getView()
方法开始,它应放在onBind()
if (isLoadingFirstTime || position == last - 1) {
if (position == last - 1) {
// Inflate the buttons layout
} else {
// Do as you already did...
}
}
答案 2 :(得分:1)
最后我得到了解决方案,我现在正在ViewGroup
中传递LayoutInflater
,其中包含我的页脚布局,然后在我的ViewGroup
中,我正在通过我的按钮,最后我在列表视图中添加页脚视图。
LayoutInflater inflater = getLayoutInflater();
ViewGroup footer = (ViewGroup) inflater.inflate(R.layout.footer_view, mListView, false);
mListView.addFooterView(footer, null, false);
mListView.setAdapter(mAdapter);
final Button footerRefreshBtn = (Button) footer.findViewById(R.id.footerRefreshBtn);
footerRefreshBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
footerRefreshBtn.setVisibility(View.GONE);
populateNotifications(10);
}
});
答案 3 :(得分:0)
这样做
main_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linTop"
android:layout_marginBottom="10dp" >
</ListView>
<LinearLayout
android:id="@+id/linTop"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Done"
android:textSize="15sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Cancel"
android:textSize="15sp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Select All"
android:textSize="15sp" />
</LinearLayout>
</RelativeLayout>