【发布时间】:2019-12-28 11:33:01
【问题描述】:
每次按下按钮时都会调用此函数,它会添加一张具有分配给该卡的名称的新卡。按下卡片的“x”图标时,如何移除特定卡片?
// 按下按钮时创建单个卡片的功能
public void cardview1()
{
text2 = v1.findViewById(R.id.dev_name);
dev_id1 = v1.findViewById(R.id.dev_id);
cardview2 = new CardView(getApplicationContext());
cardview2.setFocusable(false);
cardview2.setClickable(false);
layoutparams1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutparams1.setMargins(19, 83, 19, 0);
lay1 = new LinearLayout(this);
lay1.setOrientation(LinearLayout.VERTICAL);
layoutparams2 = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, 115);
lay2 = new LinearLayout(this);
lay2.setLayoutParams(layoutparams2);
lay2.setOrientation(LinearLayout.HORIZONTAL);
layoutparams3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
lay6 = new LinearLayout(this);
lay6.setWeightSum(12);
lay6.setLayoutParams(layoutparams3);
lay6.setPadding(10,40,0,0);
lay6.setOrientation(LinearLayout.HORIZONTAL);
cardview2.setLayoutParams(layoutparams1);
cardview2.setCardBackgroundColor(Color.parseColor("#2fffffff"));
cardview2.setMinimumHeight(330);
cardview2.addView(lay1);
dev_text1 = new TextView(getApplicationContext());
dev_text1.setText(dev_name1.getText().toString().trim()+" ");
dev_text1.setPadding(20, 15,0,0);
dev_text1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 26);
dev_text1.setTypeface(null, Typeface.BOLD);
dev_text1.setTextColor(Color.GRAY);
sw0 = new Button(getApplicationContext());
sw0.setText(" X");
sw0.setTextSize(20);
sw0.setTypeface(null, Typeface.BOLD);
sw0.setBackgroundResource(0);
sw0.setTextColor(Color.GRAY);
sw0.setPadding(0,0,0,5);
sw0.setLayoutParams(new LinearLayout.LayoutParams(70, 70));
lay1.addView(lay2);
lay1.addView(lay6);
lay2.addView(dev_text1);
lay2.addView(sw0);
ahomeLayout.removeView(atv);
ahomeLayout.addView(cardview2);
saveInPref();
}
【问题讨论】:
标签: java android android-recyclerview android-cardview