/mainActivity.java Secret
Created
August 19, 2020 07:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.appcompat.app.AppCompatActivity; | |
import androidx.fragment.app.Fragment; | |
import androidx.fragment.app.FragmentManager; | |
import androidx.lifecycle.ViewModelProvider; | |
import android.os.Bundle; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ | |
private ViewModelPractice viewModelPractice; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
viewModelPractice = new ViewModelProvider(this).get(ViewModelPractice.class); | |
Fragment fg = new FragmentPractice(); | |
FragmentManager fragmentManager = getSupportFragmentManager(); | |
fragmentManager.beginTransaction().add(R.id.fragment_container,fg).commit(); | |
} | |
@Override | |
public void onClick(View v) { | |
switch (v.getId()){ | |
case R.id.change_value_button : | |
viewModelPractice.setValueOfLiveData(viewModelPractice.getValue()+1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment