简体   繁体   English

必需的android.support.v4.app.fragment

[英]required android.support.v4.app.fragment

i have simple project that have list view when any one click on any item on list view open in single window by fragment the problem is that i want to replace my fragment with on of this tabs fragment on this project http://www.truiton.com/2015/06/android-tabs-example-fragments-viewpager/ 我有一个简单的项目,当任何人单击列表视图中的任何项目时,都具有片段视图的单个项目在单个窗口中打开,问题是我想用该项目上此选项卡片段中的一个替换我的片段http://www.truiton .com / 2015/06 / android-tabs-example-fragments-viewpager /

i put my mainactivty class in switch case but it get to me this error in first picture i try to import import android.support.v4.app.Fragment but also the same promplem 我将mainactivty类放在开关盒中,但是在第一张图片中出现了这个错误,我尝试导入import android.support.v4.app.Fragment但也有相同的示例

this is the clases of my project ....Main2Activity class 这是我的项目的主要内容.... Main2Activity类

public class Main2Activity extends AppCompatActivity implements fragmentA.comunicatir
        {

        fragmentA f1;
        fragmentB f2;
        FragmentManager manegaer;

        @Override
        protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

                manegaer=getSupportFragmentManager();
        f1=(fragmentA)manegaer.findFragmentById(R.id.fragment1);
        f1.setcomunicatir(this);
        }


        @Override
        public void respned(int index){
                f2=(fragmentB)manegaer.findFragmentById(R.id.fragment2);

        if(f2!=null&&f2.isVisible()){

        f2.cahngedata(index);
        }else{
        Intent intent=
        new Intent(this,
        AnotherActivity.class);
        intent.putExtra("index",index);
        startActivity(intent);
        }


        }
        }

错误2

the another classes class fragmentA 另一个类classfragmentA

 public class fragmentA extends Fragment implements AdapterView.OnItemClickListener
{
    ListView list;
    comunicatir  com;
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.fragment1,container,false);
        list=(ListView)view.findViewById(R.id.listView1);

        ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(),
                R.array.chapters, android.R.layout.simple_list_item_1);
        list.setAdapter(adapter);
        list.setOnItemClickListener(this);
        return  view;

    }

    public void setcomunicatir (comunicatir comunicator)
    {

        this.com=comunicator;
    }
    @Override
    public void onItemClick(AdapterView<?> adapterView, View veiw, int i, long l) {

        com.respned(i);

    }


    public interface comunicatir
    {
        public void respned(int index);

    }
}

    public class fragmentB  extends Fragment

{

    TextView text;
    TextView textView2;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment2, container, false);
        //text = (TextView) view.findViewById(R.id.textView1);
        //imgv=(ImageView) view.findViewById(R.id.imageView1);
        textView2 =(TextView)view.findViewById(R.id.textView22);

        return view;

    }
    public void cahngedata(int index)
    {

    /*String[] descrption =getResources().getStringArray(R.array.hadeith);
            text.setText(descrption[index]);*/

        String []Hadith=getResources().getStringArray(R.array.hadeith);
        //imgv.setImageResource(img[index]);
        textView2.setText(Hadith[index]);

        //int []descrption =getResources().getIntArray(img[index]);
        //  imgv.setImageResource(descrption[index]);       

            /*text.setText(descrption[index]);
        int arr[]=getResources().getIntArray(img[index]);
            imgv.setImageResource(arr[index]);*/


    }
}



public class AnotherActivity extends Activity

{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.another);

        Intent intent = getIntent();
        int index= intent.getIntExtra("index", 0);
        fragmentB f2= (fragmentB)
                getFragmentManager().
                        findFragmentById(R.id.fragment2);
        if (f2!=null)
            f2.cahngedata(index);

    }
}

the Another Activity class also have error in picture 2 另一个Activity类在图片2中也有错误

错误2

1st issue: You just can't put an activity on a Tab, but you probably won't need the getItem() you can delete that method 第一个问题:您只是不能在Tab上放置活动,但是您可能不需要getItem()即可删除该方法

2nd issue: 第二期:

Replace: 更换:

fragmentB f2 = (fragmentB) ...

With: 带有:

fragment f2 = (Fragment) ...

go to the tab.class which u have problem in and change import android.app.Fragment; 转到您遇到问题的tab.class并更改import android.app.Fragment; to import android.support.v4.app.Fragment; 导入android.support.v4.app.Fragment;

it will run . 它会运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有一种方法可以将片段转换为android.support.v4.app.Fragment - Is there a way to convert fragment to android.support.v4.app.Fragment 错误的第二个参数类型。 必需:“ android.support.v4.app.Fragment” - wrong 2nd argument type. required: 'android.support.v4.app.Fragment' 为什么此错误显示“不兼容的类型”。“必需:android.support.v4.app.Fragment”? - Why is this Error showing “Incompatible Types.” “Required: android.support.v4.app.Fragment”? 片段错误:所需的类型不兼容:android.support.v4.app.Fragment,找到:package_name.app_name.Fragment_name - Fragment Error: Incompatible Types Required: android.support.v4.app.Fragment, Found: package_name.app_name.Fragment_name 覆盖 android.support.v4.app.fragment 中已弃用的方法 - Override deprecated method in android.support.v4.app.fragment 在实现FragmentTabHost时将android.support.v4.app.Fragment强制转换为android.app.Fragment的可能性 - Possibility of casting android.support.v4.app.Fragment to android.app.Fragment when implementing a FragmentTabHost 无法从android.support.v4.app.Fragment转换为android.app.Fragment - Cannot convert from android.support.v4.app.Fragment to android.app.Fragment 在同一活动中使用android.support.v4.app.Fragment和android.app.Fragment - Use android.support.v4.app.Fragment and android.app.Fragment in same activity 类型不匹配:无法从android.support.v4.app.Fragment转换为android.app.Fragment - Type mismatch: cannot convert from android.support.v4.app.Fragment to android.app.Fragment 使用backstack时android.app.Fragment和android.support.v4.app.Fragment的不同行为 - Different behavior of android.app.Fragment and android.support.v4.app.Fragment while using backstack
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM