0

Ich kann das RecyclerView nicht zu meinem Fragment hinzufügen. die Superklasse "RecyclerView" erscheint in roter Farbe. hilf mir!Dem Fragment kann keine recyclerview hinzugefügt werden

Java-Code:

package com.invincible.fragedit; 

import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 


public class TableList extends Fragment { 

    private RecyclerView recyclerView;//error line 
    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
     return inflater.inflate(R.layout.fragment_list_table,container,false); 
    } 
} 

Ich habe bereits eine recyclerview in der XML-Datei des Fragments gebunden, aber ich kann nicht Gegenstand von RecyclerView in meiner Fragment Klasse

xml-Code machen:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="400dp" 
    android:id="@+id/frag_2" 
    android:layout_marginTop="80dp" 
    android:background="#c61414" 
    tools:context="com.invincible.fragedit.ListTable"> 

    <!-- TODO: Update blank fragment layout --> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    </android.support.v7.widget.RecyclerView> 

    <TextView 
     android:id="@+id/table_value" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 
+0

Haben Sie die JAR-Datei als Bibliothek zum Projekt hinzugefügt? –

+0

Haben Sie die Abhängigkeit 'compile' com.android.support: appcompat-v7: 25.1.1'' in Ihrem 'build.gradle' hinzugefügt? – Kapouter

Antwort

0

Fügen Sie einen Import in Ihr Fragment hinzu und prüfen Sie, ob Sie es in Ihr build.gradle wie dieses compile 'com.android.support:recyclerview-v7:25.1.0' hinzugefügt werden.

import android.support.v7.widget.RecyclerView; 
+0

fertig! aber es ist immer noch ein Fehler im Import-Paket sowie in der Fragment-Klasse –

+0

@ashu_legacy aktualisiert meine Antwort –

+0

Danke, es hat funktioniert! :) –

0

stellen Sie sicher, dass Sie in build.gradle

compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'com.android.support:design:23.1.1' 
    compile 'com.android.support:cardview-v7:23.1.1' 
    compile 'com.android.support:recyclerview-v7:23.1.1' 
0

in Ihrer Java-Klasse import-Anweisung hinzufügen wird für Recycler Ansicht fehlt. Bitte führen Sie die folgenden Schritte aus.

1- Fügen Sie folgende Zeilen in der Datei build.gral 'compile' com.android.support:appcompat-v7:25.0.1 '' hinzu. 2- Reinigen und erneut erstellen.

3- Fügen Sie diese Zeile in Ihren Importbereich ein 'importieren Sie android.support.v7.widget.RecyclerView';

Verwandte Themen