我正在使用芳香剂在我的应用程序中编写菜单。 我收到以下错误: “第二个参数类型错误。找到:'com.example.liadrosenberg.application.MenuActivitys.MyAccountActivity',必需:'android.support.v4.app.Fragment'more ...”
我添加了
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:21.+'
到我的build.gradel文件。什么都没有改变。 这些问题仅发生在nav_Account菜单上。
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_Gates) {
FragmentTransaction ft= getSupportFragmentManager().beginTransaction();
ft.replace(R.id.Count,new MyGatesActivity()).commit();
} else if (id == R.id.nav_Settings) {
FragmentTransaction ft= getSupportFragmentManager().beginTransaction();
ft.replace(R.id.Count,new SettingsActivity()).commit();
} else if (id == R.id.nav_Account) {
FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
ft.replace(R.id.Count,new MyAccountActivity()).commit();
} else if (id == R.id.nav_About) {
FragmentTransaction ft= getSupportFragmentManager().beginTransaction();
ft.replace(R.id.Count,new SettingsActivity()).commit();
}
我的帐户活动:
package com.example.liadrosenberg.application.MenuActivitys;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.liadrosenberg.application.R;
public class MyAccountActivity extends Fragment {
@Override
@Nullable
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_my_account, container, false);
return view;
}
}
非常感谢您!
答案 0 :(得分:2)
在您的MyAccountActivity
中,使用支持库中的Fragment
。
使用此导入:
import android.support.v4.app.Fragment;