Fragment和ListFragment之间不兼容

时间:2016-12-27 20:15:32

标签: android listview android-fragments android-listfragment

注意 :我看过类似的问题。他们中的大多数人都说要在https://success.jitterbit.com/display/DOC/REST+Transformation+-+Sugar+CRM+-+Request+Session+Token https://success.jitterbit.com/display/DOC/oAuth+1.0a+with+Twitter 之间进行交流;然而,这并没有解决我的问题。

我做了import android.app.ListFragment名为import android.support.v4.app.ListFragment。我尝试使用FragmentfragmentOne中实施列表。单击特定按钮时,屏幕上将显示fragmentOne。按下ListFragment按钮时要调用的方法是FragmentOne。它位于fragmentOne。但是,在这个方法中,行:

FragmentOneClick(View v)

我收到一条错误说:

  

不兼容的类型。必需:android.app.ListFragment   发现:com.example.projectName.fragmentOne

如何解决此错误?

MainActivity.java

  Fragment myFragment=new fragmentTwo();

FragmentOne.xml:

fragmentOne.java

MainActivity.java:

import android.app.ListFragment;
import android.content.Context;
import android.net.Uri; 
import android.os.Bundle;
//import android.support.v4.app.Fragment;
import android.app.Fragment;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;


public class fragmentOne extends android.support.v4.app.ListFragment
{
    String dates[]={"1","2","3","4","5","6","7","8","9"};


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        View rootView;
        rootView=inflater.inflate(R.layout.fragment_fragment_one, container, false);

        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState)
    {
        super.onActivityCreated(savedInstanceState);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,dates);
        setListAdapter(adapter);
    }
}

0 个答案:

没有答案