Skip to content Skip to sidebar Skip to footer

Findviewbyid In Static Method In Different Class

Inside on of my android fragments I have the following simple check as to whether my app runs on a tablet or not (on a tablet I have 3 views open, view 2 and 3 are not seen on a ph

Solution 1:

It looks like you're searching for a quick-and-dirty solution, so here are two:

  • Change the method signature's to take the activity as a parameter:

    public static boolean landscapeChecker(Activity activity).

    In the method, use the passed-in activity in place of getActivity(). Call it from your various activities like boolean mDualPane = landscapeChecker(this).

  • Subclass Activity and put the method there instead. For this solution, you would create a class MyActivity extends Activity, then make your various activities extend MyActivity instead of extend Activity. In the method, use this in place of getActivity().

Solution 2:

you just declare on MainActivity static element before oncreate . after this create a metod on bottom;

staticTextView textView;

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
.....................................................

textView = (TextView) findViewById(R.id.texview);
}

publicstaticvoidupTex(String up) {


        textView.setText(up);
    }


}

//other file classpublicclassother{

   publicvoidmethod(){
     upText("jaja");
 }

Post a Comment for "Findviewbyid In Static Method In Different Class"