- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 fragment 中实现寻呼机,但出现此错误
The method getSupportFragmentManager() is undefined for the type
HowToUse_phone
在
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
这里是代码,
package com.chocte.ks_documents;
import java.util.Locale;
import android.os.Bundle;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
public class HowToUse_phone extends SherlockFragment{
private LinearLayout lLayoutFrgHow;
ViewPager mViewPager;
SectionsPagerAdapter mSectionsPagerAdapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
//return inflater.inflate(R.layout.activity_how_phone, container, false);
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
//mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager = (ViewPager) getView().findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
//get the layou8t
lLayoutFrgHow=(LinearLayout) inflater.inflate(R.layout.activity_how_phone, container, false);
return lLayoutFrgHow;
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
//return getString(R.string.title_section1).toUpperCase(l);
return "a";
case 1:
//return getString(R.string.title_section2).toUpperCase(l);
return "b";
case 2:
//return getString(R.string.title_section3).toUpperCase(l);
return "c";
}
return null;
}
}
/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main_dummy,
container, false);
TextView dummyTextView = (TextView) rootView
.findViewById(R.id.section_label);
dummyTextView.setText(Integer.toString(getArguments().getInt(
ARG_SECTION_NUMBER)));
return rootView;
}
}
}
我在导入 fragment 时看到了一些问题,但正如您在我的代码中看到的,im android.support.v4.app...
还有什么问题?
谢谢!
最佳答案
不是调用 getSupportFragmentManager()
,而是调用 getSherlockActivity().getSupportFragmentManager()
。您现在正尝试从 SherlockActivity
调用方法,但您在 SherlockFragment
中;这就是为什么您需要先获取 SherlockFragment
对象的引用 ...
但上面只会修复编译错误...我不确定您的代码中是否还有其他问题。根据之前的回答,您没有在适当的时间实例化您的 fragment View 。
关于在 fragment 上实现寻呼机的android错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18786913/
我需要能够垂直翻转一组图像。我看过使用 ViewPager,但它似乎只支持水平分页。 我也查看了 Gallery,但我也没有看到垂直分页的方法。无论如何,它已被弃用,取而代之的是 Horizont
我正在使用寻呼机中内置的 View ,并且希望有一个“显示全部”选项。即显示全部 第 2 页,共 10 页。 实现这一目标的最佳方法是什么? 史蒂夫 最佳答案 史蒂文,您可以克隆您的实际显示,然后在
当我使用 vim 编辑 Markdown 文件时,我有很好的语法着色(通过 vim-markdown 和 vim-markdown-preview 插件)。 当我使用 less(寻呼机)查看文件时,我
在我的 Android 应用程序中,我已经能够在一段时间后自动滚动查看寻呼机。我找不到显示滚动发生前剩余时间的寻呼机指示器。 我在下面附上了一个网站的屏幕截图,以了解我想要实现的目标。 如果您可以共享
当您编写的每个代码都立即运行并且您未按时完成计划时,您是否知道这种感觉:-P 就像'哦,是的,现在我有时间让它变得完美'。这就是我现在的位置^^ 所以我用 JSF (ui:repeat) 实现了一个转
我在 Android 应用程序中有一个项目列表,我希望每个项目都在一个页面上。问题是每个项目都设置了一个带有 imageview 的布局,它从一个唯一的 url 下载它的图像。这有可能实现吗?如何实现
我想同步两个 View 寻呼机之间的触摸事件。我已经试过了,但没有发现任何效果。 viewPager.setOnTouchListener(new View.OnTouchListener() {
我必须构建具有无限自动滚动功能的 View 寻呼机。我还需要在 View 寻呼机下方显示一个页面指示器,它应该根据滚动事件做出响应。目前我已经为无限自动滚动应用了以下逻辑: public void s
我正在尝试按照一些教程使用 View 寻呼机创建一个自动图像 slider 。我让一切正常,但后来我看到了 编舞:跳过 1 帧!应用程序可能在其主线程上做了太多工作。 并搜索了错误。` 你看,在我的代
如何从viewpager的第0个index跳转到view pager的最后一个index?那就是如何让view pager循环呢?如果用户向左滑动,我想跳转到最后一个索引;如果用户向右滑动,我想从最后
我在一个 iOS 应用程序上工作,它从服务器获取视频和图像,每个对象都有很多图像和视频,我需要在 slider (寻呼机)中显示这些图像和视频,用户可以在其中滑动以获取下一个,并且我需要将这些视频和图
我们目前正在使用 VS 2008 C# 开发 Windows 窗体应用程序。此应用程序用于阅读长(200 - 300 页)的法律文件,它处理大约 30 - 40 个文档。应用程序在文档文本中搜索,在文
我正在开发一个项目,其中我在一个屏幕上使用 View Pager,如下所示: 但是你可以在那里看到,有一个上层布局,其中列出了根据显示的页面选择的年份。当我们滑动 View 寻呼机时,年份也会根据显示
我需要在带有图像的 View 寻呼机文件中获取页面指示器。这是我的代码。 public class IndicatorActivity extends Activity { /** Called w
有没有办法用代表每张幻灯片的单词替换寻呼机中 slider 的圆圈(就像可单击的菜单,滑动其下方的内容)?选项在这里http://bxslider.com/options但不确定哪一个可以实现这一目标
ViewPager 叠加在 fab 之上。如何将 fab 放在首位? xml: 或者也许这不是原因?当我在上面时,只是没有按下按钮,但选项卡被翻转。 最佳答案 Coordinat
我正在尝试实现一个垂直可滑动的ViewPager,它有一堆卡片,就像外观一样。 我能够使用 ViewPager.PageTransformer 并交换触摸点来实现 VerticalViewPager。
我无法以编程方式创建和添加 View 寻呼机。 我找到了这个问题Android create ViewPager programmatically但接受的答案对我不起作用。 相关代码如下。
我有一个 View 寻呼机,其中每个页面都是一个自定义 View ( ... 而不是 Fragment ),我正在使用 LayoutInflator 进行扩充。 .每个自定义 View 都有一个 Im
我已经使用 jQuery 设置了一个动画 slider : jsFiddle 演示:http://jsfiddle.net/neal_fletcher/9zRDV/ 原因是我想在幻灯片上实现轻微的悬垂
我是一名优秀的程序员,十分优秀!