我想实现像下面的图像一样的SwipeListView,我已经为此下载了github代码SwipeListView并对其进行了更改,但它失败了我想要实现的内容
我想实现当用户向左侧滑动listitem时,应在右侧显示两个或三个按钮
我在上面的代码中进行了更改,如下面的代码
com.aug.swipe / MainActivity.java
protected View generateRightView(final int position) {
LinearLayout lnv_right = new LinearLayout(MainActivity.this);
LayoutParams lnv_params = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lnv_right.setOrientation(LinearLayout.HORIZONTAL);
TextView deleteView = new TextView(mContext);
LinearLayout.LayoutParams lp = new LayoutParams(200, 100);
deleteView.setLayoutParams(lp);
deleteView.setText("delete ");
deleteView.setGravity(Gravity.CENTER);
deleteView.setBackgroundColor(Color.parseColor("#12c2c2"));
deleteView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "del " + mList.get(position),
Toast.LENGTH_SHORT).show();
mList.remove(position);
notifyDataSetChanged();
}
});
TextView editView = new TextView(mContext);
LinearLayout.LayoutParams edt_lp = new LayoutParams(200, 100);
editView.setLayoutParams(edt_lp);
editView.setText("delete ");
editView.setGravity(Gravity.CENTER);
editView.setBackgroundColor(Color.parseColor("#12c2c2"));
editView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "del " + mList.get(position),
Toast.LENGTH_SHORT).show();
mList.remove(position);
notifyDataSetChanged();
}
});
lnv_right.addView(editView);
lnv_right.addView(deleteView);
lnv_right.setLayoutParams(lnv_params);
return lnv_right;
}
但这不起作用,需要任何解决方案
答案 0 :(得分:1)
请使用以下代码代替您的代码:
LayoutParams lnv_params = new LayoutParams(400, 100);