Skip to content

Instantly share code, notes, and snippets.

@amit-bhandari
Created April 14, 2019 13:51
Show Gist options
  • Save amit-bhandari/d63b3d03677a5bab26e9c59c89a6bfb9 to your computer and use it in GitHub Desktop.
Save amit-bhandari/d63b3d03677a5bab26e9c59c89a6bfb9 to your computer and use it in GitHub Desktop.
public class FragmentQuote extends LifecycleFragment{
private QuoteViewModel quoteViewModel;
private TextView quotetv;
private TextView authortv;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_quote,container,false);
quotetv = (TextView) view.findViewById(R.id.quote);
authortv = (TextView) view.findViewById(R.id.author);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
quoteViewModel = ViewModelProviders.of(this).get(QuoteViewModel.class);
quoteViewModel.init( getArguments().getString(Constants.stringConstants.CATEGORY_ID), Constants.quoteParam.count);
quoteViewModel.getQuote().observe(this, new Observer<Quote>() {
@Override
public void onChanged(@NonNull Quote quote) {
quotetv.setText(quote.getQuote());
authortv.setText(quote.getAuthor());
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment