Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm working on android app that creat layout with textView & checkbox programmatically for each text user input in EditText, and when the user select one of the checkbox and click on delete button the layout that contain that checkbox remove from the main layout.
But when I click on delete button just the last layout removed, and that not what I want.


What I have tried:

public void plusBtn(View view)
	{
		item = actv.getText().toString(); // text from EditText
		actv.setText("");
		creatt();
		
	}
	
	public void deletBtn(View view)
	{
		if(chbox.isChecked()){
		
			linear.removeView(linr);
			}	
	}
	public void creatt()
	{
		linr = new LinearLayout(this);
		linr.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
		linr.setOrientation(LinearLayout.HORIZONTAL);
		linr.setGravity(Gravity.RIGHT);
		TextView txt = new TextView(this);
		txt.setText(item);
		linr.addView(txt);
		chbox = new CheckBox(this);
		linr.addView(chbox);
		linear.addView(linr); // main layout
	}
Posted
Comments
Richard MacCutchan 2-Aug-21 9:14am    
Your remove code is just removing the last view that was created. You need to find its reference based on which checkbox is set.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900