我一直在使用支持库的一些问题,我试图从一个活动调用一个片段,但它一直说我创建的片段类不支持转换为app.support.v4或“不兼容的类型” “事情是我不知道如何使我创建的片段类与v4兼容,这里是错误的地方:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.blitzar.stiktag.ImageSliderFragment;
import com.blitzar.stiktag.R;
public class ItemDescriptionActivity extends FragmentActivity {
private Fragment contentFragment;
ImageSliderFragment imageSliderFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_description);
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.findFragmentByTag(ImageSliderFragment.ARG_ITEM_ID) != null) {
imageSliderFragment = fragmentManager
.findFragmentByTag(ImageSliderFragment.ARG_ITEM_ID);
contentFragment = imageSliderFragment;
}
} else {
imageSliderFragment = new ImageSliderFragment();
switchContent(imageSliderFragment, ImageSliderFragment.ARG_ITEM_ID);
}
这是骚扰的代码块:
imageSliderFragment = fragmentManager
.findFragmentByTag(ImageSliderFragment.ARG_ITEM_ID);
contentFragment = imageSliderFragment;
ImagSliderFragment是我创建的片段类,请高度重视任何帮助,谢谢!
答案 0 :(得分:1)
在你的片段类中,确保导入
android.support.v4.app.Fragment
;
答案 1 :(得分:1)
检查您的ImageSliderFragment
它应该有一行
import android.app.Fragment;
将其更改为
import android.support.v4.app.Fragment;