Ich möchte, klicken Sie auf meine benutzerdefinierte Element hinzuzufügen:Klicken Sie auf benutzerdefinierte Artikel mit butter android
public class ContactItem extends FrameLayout {
@BindView(R.id.itemHeader)
TextView textLabel;
@BindView(R.id.itemValue)
TextView textValue;
@BindView(R.id.imageIcon)
ImageView icon;
@BindView(R.id.mainLayout)
RelativeLayout mainLayout;
private String label = null;
public ContactItem(Context context) {
super(context);
init(context, null);
}
public ContactItem(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public ContactItem(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.textLabel);
label = a.getString(R.styleable.textLabel_text_attr);
}
addView(inflate(context, R.layout.item_contact, null));
ButterKnife.bind(this);
}
public TextView getTextLabel() {
return textLabel;
}
public TextView getTextValue(){
return textValue;
}
public ImageView getIcon(){
return icon;
}
public void setTextLabelText(int text){
textLabel.setText(text);
}
public void setTextValueText(String text){
textValue.setText(text);
}
public void setIconRes(int res){
icon.setImageResource(res);
}
}
In meiner Tätigkeit ich diese Art einige Elemente hinzuzufügen.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/color_white">
<TextView
android:id="@+id/Header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingTop="20dp"
android:textAllCaps="true"
android:textStyle="bold"
android:background="@color/background"/>
<views.items.ContactItem
android:id="@+id/contactTelefon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
<views.items.ContactItem
android:id="@+id/contactEmail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
</LinearLayout>
jetzt, wenn ich auf Artikel CONTACT klicken Ich möchte E-Mail senden und wenn contactTelefon möchte ich einen Anruf tätigen. Ich habe Funktionen, aber onClick funktioniert nicht. Irgendwelche Ideen?
@OnClick(R.id.contactTelefon)
public void clickOnCall(){
presenter.callFunction());
}
keine Ergebnisse ... :( – edi233
@ edi233 Ich habe meine Antwort bearbeitet –