我是应用程序开发的初学者,我喜欢问一个问题,我尽力在谷歌中找到答案,但我失败了。所以,
在我的应用程序(在java中)中,我也使用文本字段:
<com.google.android.material.textfield.TextInputLayout
android:layout_marginBottom="20dp"
android:id="@+id/start_date_Layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
app:helperText="Start Date"
app:endIconMode="custom"
app:endIconDrawable="@drawable/ic_date"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/start_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="dd/mm/yy"
/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我向我的结束图标添加了一个监听器,如下所示:
this.startDateLayout = v.findViewById(R.id.start_date_Layout);
this.startDateLayout.setEndIconOnClickListener(this);
Run Code Online (Sandbox Code Playgroud)
我的问题是当我尝试获取用户单击的视图时:
@Override
public void onClick(View v) {
if (v.getParent() == this.startDateLayout){
Toast.makeText(this.context, "click", Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
toast 永远不会出现,并且 if 条件永远不会成立,我的问题是如何获取用户点击的视图。感谢您的阅读,我希望我尽可能清楚。