Friday, 6 September 2013

How to call non static method from main class

How to call non static method from main class

I just ran into this problem while coding android. If I have a non-static
method (It has to be non-static for the code inside to work) in my main
class, how am i supposed to call it from within another class, because
obviously I can't create another instance of my main class without
starting a new instance of the program?
public class MainActivity extends FragmentActivity {
public static String starttime = "";
public static String startdate = "";
public static String endtime = "";
public static String enddate = "";
public static boolean start = false;
}
public void setDateText() {
EditText TextStart = (EditText)findViewById(R.id.txt_start);
TextStart.setText(startdate + " at " + starttime,
TextView.BufferType.NORMAL);
EditText TextEnd = (EditText)findViewById(R.id.txt_end);
TextEnd.setText(enddate + " at " + endtime, TextView.BufferType.NORMAL);
}
Any help on how to call the setDateText() method from another class?
Thanks in advance

No comments:

Post a Comment