1

mir helfen, das Problem zu lösen, versuchte ich es auf meinem logcat und die Linie von DatabaseListFragment scheinen gibt mir einen Fehler in den Adapter einstellen:CardView Recycler ist nicht mit meiner Liste arbeiten <SomeModel>

recyclerView.setAdapter(adapter); // THE ERROR GOES HERE 

Oder ist es mein RecyclerAdapter hat es einen Fehler?

Hier ist meine Tätigkeit als DatabaseListFragment

public class DatabaseListFragment extends Fragment { 
    private DatabaseAccess db; 

    public DatabaseListFragment() { 
     // Required empty public constructor 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
     db = DatabaseAccess.getInstance(getActivity().getApplicationContext()); 
     db.open(); 
     List<TranslateModel> quotes = db.getAllTranslations(); 
     db.close(); 
     //View header = inflater.inflate(R.layout.listview_header_row, null); 
     View view = inflater.inflate(R.layout.listview_item_row, container, false); 

     RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.listView); 
     RecyclerAdapter adapter = new RecyclerAdapter(getActivity(), quotes); 
     recyclerView.setAdapter(adapter); // THE ERROR GOES HERE 
     recyclerView.setHasFixedSize(true); 
     recyclerView.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext())); 
     return view; 
    } 
} 

listview_item_row.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="5dp"> 

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/lang_list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    card_view:cardCornerRadius="5dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/icon_lang" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:layout_margin="5dp" 
      android:background="@drawable/circular_textview" 
      android:fontFamily="sans-serif-thin" 
      android:gravity="center" 
      android:text="SA" 
      android:textAllCaps="true" 
      android:textColor="#FFF" 
      android:textSize="32sp" /> 

     <TextView 
      android:id="@+id/txtID" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:layout_toRightOf="@id/icon_lang" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp" 
      android:paddingTop="10dp" 
      android:text="Starting Android" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txtArabic" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/txtID" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="5dp" 
      android:layout_toRightOf="@id/icon_lang" 
      android:padding="5dp" 
      android:text="arab" /> 
     <TextView 
      android:id="@+id/txtEnglish" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/txtID" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="5dp" 
      android:layout_toRightOf="@id/txtArabic" 
      android:padding="5dp" 
      android:text="english" /> 

     <TextView 
      android:id="@+id/txtStructure" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/txtID" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="5dp" 
      android:layout_toRightOf="@id/txtEnglish" 
      android:padding="5dp" 
      android:text="structure" /> 
    </RelativeLayout> 
</android.support.v7.widget.CardView> 

Mein MODEL:

public class TranslateModel { 

//private variables 
public int _id; 
public String _english; 
public String _arabic; 
public String _structure; 

// Empty constructor 
public TranslateModel(){ 

} 
// constructor 
public TranslateModel(int id, String english, String arabic, String structure){ 
    this._id = id; 
    this._english = english; 
    this._arabic = arabic; 
    this._structure = structure; 
} 

// constructor 
public TranslateModel(int id, String english, String _arabic){ 
    this._id = id; 
    this._english = english; 
    this._arabic = _arabic; 
} 

und meine RecyclerAdapter.java

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerViewHolder> { 

List<TranslateModel> mTModel; 
Context context; 

LayoutInflater inflater; 
public RecyclerAdapter(Context context, List<TranslateModel> tModel) { 
    this.context = context; 
    inflater = LayoutInflater.from(context); 
    mTModel = tModel; 
} 

@Override 
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View v = inflater.inflate(R.layout.listview_item_row, parent, false); 
    RecyclerViewHolder viewHolder = new RecyclerViewHolder(v); 
    return viewHolder; 
} 

@Override 
public void onBindViewHolder(RecyclerViewHolder holder, int position) { 

    // Get the data model based on position 
    TranslateModel translate = mTModel.get(position); 
    //holder._id.setText(name[position]); 
    holder._id.setText(translate._id); 
    holder._arabic.setText(translate._arabic); 
    holder._english.setText(translate._english); 
    holder._structure.setText(translate._structure); 

    holder._icon.setText(translate._id); 

    holder._icon.setOnClickListener(clickListener); 
    holder.imageView.setTag(holder); 
} 

private View.OnClickListener clickListener = new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 

     RecyclerViewHolder vholder = (RecyclerViewHolder) v.getTag(); 
     int position = vholder.getPosition(); 

     Toast.makeText(context,"This is position " + position, Toast.LENGTH_LONG).show(); 
    } 
}; 

@Override 
public int getItemCount() { 
    return (null != mTModel ? mTModel.size() : 0); 
} 
} 

EDIT: Hier ist mein Log ... Fehler starten von hier ...

I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performSaveInstanceState (Landroid/os/Bundle;)V from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performSaveInstanceState, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5126: Landroid/support/v4/app/Fragment;.performSaveInstanceState (Landroid/os/Bundle;)V 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0073 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.restoreViewState (Landroid/os/Bundle;)V from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.restoreViewState, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5132: Landroid/support/v4/app/Fragment;.restoreViewState (Landroid/os/Bundle;)V 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0095 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performCreateView (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Landroid/os/Bundle;)Landroid/view/View; from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performCreateView, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5113: Landroid/support/v4/app/Fragment;.performCreateView (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Landroid/os/Bundle;)Landroid/view/View; 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x00d3 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performPrepareOptionsMenu (Landroid/view/Menu;)Z from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performPrepareOptionsMenu, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5123: Landroid/support/v4/app/Fragment;.performPrepareOptionsMenu (Landroid/view/Menu;)Z 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x00e1 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performStop()V from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performStop, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5128: Landroid/support/v4/app/Fragment;.performStop()V 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x00f7 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performCreateOptionsMenu (Landroid/view/Menu;Landroid/view/MenuInflater;)Z from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performCreateOptionsMenu, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5112: Landroid/support/v4/app/Fragment;.performCreateOptionsMenu (Landroid/view/Menu;Landroid/view/MenuInflater;)Z 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x011d 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performOptionsItemSelected (Landroid/view/MenuItem;)Z from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performOptionsItemSelected, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5119: Landroid/support/v4/app/Fragment;.performOptionsItemSelected (Landroid/view/MenuItem;)Z 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x020d 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performDetach()V from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performDetach, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5116: Landroid/support/v4/app/Fragment;.performDetach()V 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0255 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performMultiWindowModeChanged (Z)V from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performMultiWindowModeChanged, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5118: Landroid/support/v4/app/Fragment;.performMultiWindowModeChanged (Z)V 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x02d9 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performConfigurationChanged (Landroid/content/res/Configuration;)V from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performConfigurationChanged, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5109: Landroid/support/v4/app/Fragment;.performConfigurationChanged (Landroid/content/res/Configuration;)V 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0313 
I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performResume()V from Lcom/eng/arab/tranlator/androidtranslator/fragment/DatabaseListFragment;) 
I/dalvikvm: Could not find method android.support.v4.app.Fragment.performResume, referenced from method com.eng.arab.tranlator.androidtranslator.fragment.DatabaseListFragment.access$super 
W/dalvikvm: VFY: unable to resolve virtual method 5125: Landroid/support/v4/app/Fragment;.performResume()V 
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0385 
Disconnected from the target VM, address: 'localhost:9662', transport: 'socket'` 
+0

Bitte das Protokoll schreiben. – sJy

+0

Weisen Sie den ersten Layout-Manager zu und setzen Sie dann den Adapter. Das könnte Ihr Problem lösen – Vickyexpert

+0

Ich habe es versucht, aber immer noch nicht funktioniert ... – Ric17101

Antwort

0

Nun .. Sie sollten schreiben Ihr Logcat mit Fehler.

ist jedoch ein Fehler setAdapter() nennen, bevor die LayoutManager

So einstellen, versuchen Sie den Code wie folgt zu aktualisieren:

recyclerView.setHasFixedSize(true); 
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); 

recyclerView.setAdapter(adapter); // THE ERROR GOES HERE 
+0

Gleiches Ergebnis sir ... – Ric17101