0

Überprüfen Sie einfach die Hauptaktivität .xml was ich tue ist Recycler anzeigen unter einer Schaltfläche angezeigt und Text bearbeiten .. der Wert von Text bearbeiten ist in einer Karte gemacht, aber das Problem die Taste funktioniert nicht, ich weiß nicht, warumRecycler Ansicht und Kartenansicht funktioniert nicht richtig

helfen plz ich bin neu in Coordinator Ansichten mich so plz verzeihen, wenn ich

AdapterEx.java einige Noob Fehler machen

import android.support.design.widget.Snackbar; 
import android.support.v7.widget.RecyclerView; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TextView; 

import java.util.List; 

public class AdapterEx extends RecyclerView.Adapter<AdapterEx.ViewHolder>{ 

    private List<String> nos; 


    public AdapterEx(List<String> nos){ 
     this.nos = nos; 
    } 

    class ViewHolder extends RecyclerView.ViewHolder{ 

     public TextView number; 

     public ViewHolder(View itemView) { 
      super(itemView); 
      number = 
        (TextView)itemView.findViewById(R.id.nos); 

      itemView.setOnClickListener(new View.OnClickListener() { 
       @Override public void onClick(View v) { 
        int position = getAdapterPosition(); 

        Snackbar.make(v, "Click detected on item " + position, 
          Snackbar.LENGTH_LONG) 
          .setAction("Action", null).show(); 

       } 
      }); 
     } 
    } 

    @Override 
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { 
     View v = LayoutInflater.from(viewGroup.getContext()) 
       .inflate(R.layout.card, viewGroup, false); 
     ViewHolder viewHolder = new ViewHolder(v); 
     return viewHolder; 
    } 

    @Override 
    public void onBindViewHolder(ViewHolder viewHolder, int i) { 
     viewHolder.number.setText(nos.get(i)); 
    } 

    @Override 
    public int getItemCount() { 
     return nos.size(); 
    } 
} 

Initialisierung recycle r Ansicht

recycler = (RecyclerView) findViewById(R.id.rv); 
     LayoutManager manager = new LinearLayoutManager(this); 
     recycler.setLayoutManager(manager); 
     nos = new ArrayList<>(); 
     nos.add("sadasd"); 
     nos.add("sdada"); 
     adapter = new AdapterEx(nos); 
     recycler.setAdapter(adapter); 
     recycler.setHasFixedSize(true); 
     recycler.setItemAnimator(new DefaultItemAnimator()); 

Haupttätigkeit. xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.dev99.mathbuddy.prime" 
    android:id="@+id/prime" 
    android:background="@drawable/prime"> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:inputType="number|numberDecimal|numberSigned"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="FACTORISE IT!" 
     android:id="@+id/button5" 
     android:onClick="checker" 
     android:nestedScrollingEnabled="false" 
     android:layout_below="@+id/editText" 
     android:layout_centerHorizontal="true" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/editText2" 
     android:layout_below="@+id/button5" 
     android:textAlignment="center" 
     android:textSize="30dp" 
     android:textColor="#000000" 
     android:layout_alignParentStart="false" 
     android:layout_alignParentLeft="false" /> 

</RelativeLayout> 

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

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

Karte view.xml

<?xml version="1.0" encoding="utf-8"?> 

<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/card_view" 
    android:layout_gravity="center_horizontal" 
    android:layout_width="match_parent" 
    android:layout_margin="10dp" 
    android:layout_height="wrap_content" 
    card_view:cardCornerRadius="4dp" 
    card_view:cardBackgroundColor="@color/bluemat" 
    card_view:cardElevation="10dp" 
    card_view:contentPadding="4dp" 
    android:clickable="true"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/nos" 
     android:textSize="40dp" 
     android:textStyle="bold" 
     android:textAlignment="center" 
     android:layout_gravity="center" 
     android:textColor="@color/red"/> 

</android.support.v7.widget.CardView> 
+0

Haben Sie Abhängigkeiten von Cardview und Recyclerview in Gradle-Datei implementiert? oder Sie können diesen Link überprüfen: https://github.com/dharmakshetri/CardViewBeispiel –

+0

ja ich habe die Abhängigkeiten angegeben und ich habe mehrere Beispiele gesehen, aber das Problem ist nicht mit der Kartenansicht Ich sage, dass die Schaltfläche und die Textansicht ** oberhalb der Recycler-Ansicht funktionieren nicht ** –

Antwort

2

Das Problem ist RecyclerView mit wrap_content. Aus irgendeinem Grund zeigt eine RecyclerView das letzte Element oder die letzten paar Elemente nicht gut an. Das am häufigsten auftretende Problem war, dass der letzte Gegenstand abgeschnitten wurde.

Verwandte Themen