단추 및 TextView가 포함 된 LabelButton이라는 맞춤 LinearLayout 클래스가 있습니다. 버튼의 onclick 리스너가 LabelButton을 삭제하도록하고 싶습니다. LabelButton의 객체에서 내 Activity 클래스로 무언가를 전달하여 주 레이아웃에서 해당 LabelButton을 제거하도록 알려주려면 어떻게해야합니까? 내 활동 클래스에서자체를 삭제할 Android onClickListener
public class LabelButton extends LinearLayout {
private OnClickListener onClick;
public LabelButton(Context context, final String text) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View labelView = inflater.inflate(R.layout.button_label, this);
TextView textView = (TextView) labelView.findViewById(R.id.textLabelText);
textView.setText(text);
Button button = (Button) labelView.findViewById(R.id.buttonCancelLabel);
onClick = new OnClickListener() {
public void onClick(View v) {
System.out.println("Button: " + text + " clicked");
// do something here to remove this button
}
};
button.setOnClickListener(onClick);
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
}
}
, 나는
//labelButtons is a List of LabelButtons
LabelButton labelButton = new LabelButton(getApplicationContext(),
txtBagLabel.getText().toString());
labelButtons.add(labelButton);
아마도 시도해 볼 수 있습니다 : labelView.setVisibility (View.GONE),하지만 확실하지 않습니다. –
해결책이 있습니까? – Salmaan