はのLinearLayoutが含まれている私のCustomViewのIDが含まれていません:生成FragmentBindingはのTextViewとのCustomViewが含まれている私はアンドロイドのプロジェクトと私のdashboard_fragment_layout.xmlでデータバインディングを使用してい
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.ui.dashboard.DashboardFragment">
<data>
<variable
name="ViewModel"
type="com.example.ui.dashboard.DashboardViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvSome"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<view
android:id="@+id/viewCustom"
class="com.example.ui.dashboard.CustomView"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal" />
</LinearLayout>
</layout>
私は、生成を経由して私のカスタムビューにアクセスしようFragmentDashboardBinding:
mCustomView = mBinding.viewCustom;
AndroidStudioで 'シンボルビューカスタムを解決できません'が表示されています。そして、私はTextViewにして、この問題を持っていない、それはmBindingオブジェクトからアクセスできます:私は常に、カスタムビューと、このエラーを取得してい
mSomeTextView = mBinding.tvSome; // all fine, no errors
、と私のカスタム・ビュー・オブジェクトにアクセスするための唯一の方法は、これを行うことですfindViewByIdと古い方法:すべて一緒に
mCustomView = view.findViewById(R.id.viewCustom); // that works
:私は、生成されたデータバインディングオブジェクトを介してカスタムビューにアクセスするにはどうすればよい
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mViewDataBinding = DataBindingUtil.inflate(inflater, fragment_dashboard_layout, container, false);
view = mViewDataBinding.getRoot();
mCustomView = mViewDataBinding.viewCustom; // 'Can't resolve symbol viewCustom
mTextView = mViewDataBinding.tvSome; // all fine
mCustomView = view.findViewById(R.id.viewCustom); // that works
}
?
ありがとうございました! –
あなたに幸運。あなたは私の答えを受け入れることができます。ありがとうございます@ VladMorzhanov – KeLiuyue