如何从MainActivity运行方法到我的值类?

时间:2013-09-23 12:23:40

标签: java android class void

我有2节课。我想这样做我可以调用方法从值到MainActivity,我不知道我是否需要使用接口(我不知道如何使用接口)

MainActivity类:

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

        }
     }
 }

价值等级:

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

    } 
}

1 个答案:

答案 0 :(得分:1)

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();
}