2017-06-06 2 views
0

Ich habe childblog.xmlWie aus Fragment Kind Blick in Adapterklasse referenzieren

<TextView        
    android:id="@+id/tv_fab1" 
    adroid:layout_width="wrap_content"        
    android:layout_height="wrap_content" 
    android:layout_marginRight="15dp" 
    android:text="Google+" 
    android:textColor="@color/white" 
    android:textSize="16dp" 
    /> 

ich die Adapterklasse haben, die die oben childblog Layout für jedes Element in der recycleview aufzublasen.

@Override 
public Holder_blog onCreateViewHolder(ViewGroup parent, int viewType) { 
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.child_blog, parent, false); 
    Holder_blog holder_blog = new Holder_blog(view); 
    return holder_blog; 
} 

Und ich versuche das Textview von childblog in meinem Fragment zu beziehen, die halten die recycleview

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_blog, container, false); 
    System.out.println("Current Class===>>>" + getClass().getSimpleName()); 
    ((MainActivity) getActivity()).enable_imv_drawer_mainactivity(); 

    tv_fab1 = (TextView) container.findViewById(R.id.tv_fab1); 

Ich habe eine Null-Objekt Referenz zu bekommen. Wie kann ich die Textansicht des Childblog im Fragment erhalten?

Antwort

0

ändern

tv_fab1 = (TextView) container.findViewById(R.id.tv_fab1); 

zu

tv_fab1 = (TextView) view.findViewById(R.id.tv_fab1); 
+0

das Ergebnis ist das gleiche ... –

Verwandte Themen