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
activityin place ofgetActivity(). Call it from your various activities likeboolean mDualPane = landscapeChecker(this).Subclass
Activityand put the method there instead. For this solution, you would create a classMyActivity extends Activity, then make your various activitiesextend MyActivityinstead ofextend Activity. In the method, usethisin place ofgetActivity().
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"