Constraint Layout에 OnClickListener를 추가 할 수 없습니다. 항상 null을 반환합니다.OnClickListener가 ConstraintLayout에 null을 반환합니다.
가 나는 ComplexButton definded 한 :
public class ComplexButton{
private TextView title;
private TextView subTitle;
private ImageView icon;
private ConstraintLayout clickableArea;
public ComplexButton(ConstraintLayout layout) {
title = (TextView) layout.findViewById(R.id.textview_title);
subTitle = (TextView) layout.findViewById(R.id.textview_button_subtitle);
icon = (ImageView) layout.findViewById(R.id.imageview_button_icon);
clickableArea = (ConstraintLayout) layout.findViewById(R.id.complex_button_clickable_area_new);
}
내가 텍스트 뷰와 이미지 뷰를 설정할 수 있습니다. 그러나 clickableArea의 경우 null을 반환합니다.
다른 클래스에서는 인스턴스를 만들어 elemets를 설정합니다.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.NotOfInterrest, container, false);
ConstraintLayout complexButtonLayout= (ConstraintLayout) view.findViewById(R.id.buttonHotspotFinder_new);
ComplexButton complexButton= new ComplexButton(complexButtonLayout);
complexButton.setTitle(getString(R.string.tab_find_hotspot));
complexButton.setSubtitle("Browse hotspots on our map");
complexButton.setImageResource(R.drawable.show_hotspots_map);
complexButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), NotOfInterrest.class);
startActivity(intent);
}
});
그리고 XML 파일 : 나는 모든 이미지와 텍스트를 설정할 수 있습니다
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/complex_button_layout"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:id="@+id/complex_button_clickable_area_new">
<ImageView
android:id="@+id/imageview_button_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/buy_hotspot_subscription" />
<ImageView
android:id="@+id/imageview_right_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_keyboard_arrow_right_black_48dp" />
<TextView
android:id="@+id/textview_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textColor="@color/colorPrimary"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/imageview_button_icon"
app:layout_constraintRight_toLeftOf="@+id/imageview_right_arrow"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textview_button_subtitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/imageview_button_icon"
app:layout_constraintRight_toLeftOf="@+id/imageview_right_arrow"
app:layout_constraintTop_toBottomOf="@+id/textview_title"
app:layout_constraintVertical_bias="0.0" />
으로는 befor을 말했다. 하지만 clickableArea null 포인터를 가져옵니다.
ConstraintLayout의 경우 "com.android.support.constraint를 컴파일하십시오 : constraint-layout : 1.0.2 '" 더 새로운 버전이 있습니까?
은 complex_butt입니다. ConstraintLayout의 인스턴스가 on_clickable_area_new입니까? –
귀하의 XML 레이아웃 –