| | |
| | | import androidx.lifecycle.ViewModelProvider; |
| | | import androidx.viewbinding.ViewBinding; |
| | | |
| | | import com.duqing.missions.base.ViewModelFactory; |
| | | import com.duqing.missions.base.activities.BaseActivity; |
| | | |
| | | import java.lang.reflect.Method; |
| | |
| | | Method method = entityClass.getMethod("inflate", LayoutInflater.class,ViewGroup.class,boolean.class);//get method from name "inflate"; |
| | | binding = (B) method.invoke(entityClass,inflater,container,false);//execute method to create a objct of viewbind; |
| | | Class<VM> vmClass = (Class<VM>) type.getActualTypeArguments()[1]; |
| | | viewModel = new ViewModelProvider(this).get(vmClass); |
| | | viewModel = new ViewModelProvider(this,getViewModelFactory()).get(vmClass); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return binding.getRoot(); |
| | | } |
| | | |
| | | public ViewModelProvider.Factory getViewModelFactory(){ |
| | | return ViewModelFactory.getInstance(); |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityCreated(@Nullable Bundle savedInstanceState) { |
| | | super.onActivityCreated(savedInstanceState); |