简体   繁体   中英

How can I run method from MainActivity to my value class?

I have 2 classes. I want to do that I can call method from value to MainActivity , I don't know if I need to use interface (I don't know how to use interface)

MainActivity class:

public class MainActivity extends Activity {
    public void name() { 
        if (Check(display_ContactsName, C) == true) {

        }
     }
 }

value class:

public class Values extends MainActivity {
    private boolean Check(String Name, Cursor C) {

    } 
}
Values class extends MainActivity so no need to create interface.You can call any method of MainActivty directly just using method name.Even you can override any method of MainActivty in your Values class.

public class MainActivity extends Activity 
{
public String caption="";

//Method 1           
public void setCaption(String caption)
{
this.caption=caption
}
//Method 2           
public String getCaption()
{
return caption;
}

}

public class Values extends MainActivity 
{
setCaption("Test Application");
Toast.makeText(getApplicationContext(),getCaption(),Toast.LENGTH_SHORT).show();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM