簡體   English   中英

不抽象,不覆蓋抽象方法

[英]Not abstract and does not override abstract method

大家好,我有這個主班

public class Home extends ActionBarActivity
    implements NavigationDrawerFragment.NavigationDrawerCallbacks, FriendsFragment.OnFragmentInteractionListener {

錯誤:(42,8)錯誤:Home不是抽象的,並且不會重寫OnFragmentInteractionListener中的抽象方法onFragmentInteraction(String)

我創建了一個導航抽屜,並希望有一個新的片段來在Home Activity上顯示另一個內容。

Android Studio告訴我使home.class抽象或實現抽象方法。

在這里里面:

 public interface OnFragmentInteractionListener {
    // TODO: Update argument type and name
    public abstract void onFragmentInteraction(String id);
}

我做到了,但沒有任何改變。 而且我無法將home類抽象化,因為那樣就無法啟動該應用了。

can't instantiate class com.myup2.up2.Home

編輯1:要調用Fragment,我想我正確實現了調用。

 public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransac = fragmentManager.beginTransaction();
    Fragment newFragment = null;
    Bundle args = new Bundle();
    switch(position) {
        case 0:

            break;
        case 1:

            break;
        case 2:
            newFragment = new FriendsFragment();
            break;
    }
    if(newFragment != null) {

        fragmentManager.beginTransaction()
                .replace(R.id.container, newFragment)
                .commit();

    }
}

感謝您的進階閱讀和幫助。

將此添加到您的活動中:

@Override
public void onFragmentInteraction(PUT PARAMETERS HERE IF ANY) {
//do something here, maybe switch to another fragment
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM