0

我有2节课。我想这样做我可以从 value 调用方法 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) {

    } 
}
4

1 回答 1

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();
}
于 2013-09-23T12:41:40.920 回答