在Android片段中滑动刷新布局

在Android片段中滑动刷新布局,android,android-fragments,noclassdeffounderror,Android,Android Fragments,Noclassdeffounderror,我试图在一个片段上实现SwipeRefreshLayout 我已经解决了它,以便在一个活动上实现它,但是当我在Fragment:java.lang.NoClassDefFoundError:com上实现它时 有人有主意吗?谢谢 没有答案/解决方案的类似帖子: 我的代码: public class Principal extends Fragment implements OnRefreshListener { SwipeRefreshLayout swipeLayout; @O

我试图在一个片段上实现SwipeRefreshLayout

我已经解决了它,以便在一个活动上实现它,但是当我在Fragment:java.lang.NoClassDefFoundError:com上实现它时

有人有主意吗?谢谢

没有答案/解决方案的类似帖子:

我的代码:

public class Principal extends Fragment implements OnRefreshListener {
    SwipeRefreshLayout swipeLayout;

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

        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.principal, container, false);

        swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorScheme(android.R.color.holo_blue_bright, 
                android.R.color.holo_green_light, 
                android.R.color.holo_orange_light, 
                android.R.color.holo_red_light);

        return view;
    }
}
和我的布局:

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.enhancedListView.EnhancedListView
        android:id="@+id/listaNoticias"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="5dp" >
    </com.enhancedListView.EnhancedListView>

</android.support.v4.widget.SwipeRefreshLayout>

将您的swipeLayout初始化放在onViewCreated(视图,捆绑包)中,而不是onCreateView(布局、充气机、视图组容器、捆绑包保存状态)

解决了:)

我的XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.enhancedListView.EnhancedListView
        android:id="@+id/listaNoticias"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="5dp" >
    </com.enhancedListView.EnhancedListView>

</android.support.v4.widget.SwipeRefreshLayout>

只需确保将刷卡刷新布局的代码放在
override-fun-onViewCreated(view:view,savedInstanceState:Bundle?{}
中,而不是
onCreateView

是的,错误是“java.lang.NoClassDefFoundError:com…”。。;我非常想看到错误的其余部分。@StephaneMathis用完整堆栈跟踪更新,那么在MainActivity的第676行是什么?@StephaneMathis Principal h=new Principal();getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,h.commit()@user3931604删除最后一行返回视图;因为onViewCreate()不应该返回任何内容;我的任务是什么@纳乔_zona3@AovinMahmud不知道是否太晚,但MyTask是BaseAyncTask,您将执行(基本上是一个线程),您必须调用swipeLayout.setRefreshing(false);在onRefresh()方法中,否则它将连续显示刷新指示器。
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

        swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorScheme(android.R.color.holo_blue_bright, 
                android.R.color.holo_green_light, 
                android.R.color.holo_orange_light, 
                android.R.color.holo_red_light);
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.enhancedListView.EnhancedListView
        android:id="@+id/listaNoticias"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="5dp" >
    </com.enhancedListView.EnhancedListView>

</android.support.v4.widget.SwipeRefreshLayout>
public class Principal extends Fragment implements OnRefreshListener {
SwipeRefreshLayout swipeLayout;

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

    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.principal, container, false);

    swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorSchemeColors(android.R.color.holo_green_dark, 
            android.R.color.holo_red_dark, 
            android.R.color.holo_blue_dark, 
            android.R.color.holo_orange_dark); (...)

@Override
public void onRefresh() {
    new myTask().execute();     
}