Using static methods in Android?

前端 未结 2 1094
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 09:35

I already made some Apps in Android and noticed that I am often using static methods.

For example I have an Class which extends PreferenceFragment. In t

2条回答
  •  死守一世寂寞
    2021-01-19 09:55

    You can use a Java property known as mirroring. Below I use the property to finish the activity.

     Button btn = new Button(getActivity().getApplicationContext());
        btn.setText("Save");
        v.addView(btn);
        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                SettingsFragment.this.getActivity().finish();            
            }
        });
    

提交回复
热议问题