[英]how can i build a card shuffling method in java for cards to go in a specific order?
[英]On a card view created dynamically, how can I remove individual cards if a delete button specific to a card is pressed?
每次按下按鈕時都會調用此函數,並添加一張具有分配給該卡的名稱的新卡。 按下卡片的“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();
}
您需要在某處存儲 Id 或 Cardviwes 本身,然后為刪除按鈕提供 ID,因此當它被點擊時,它將為您提供被點擊卡的 ID,然后您可以刪除該卡。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.