2016-07-26 7 views
1

Ich habe ein Problem mit Recycleview in linearLayout. Im folgenden Code Wenn ich auf den Chat-Bereich klicke (Lineares Layout), wird Toast nicht sichtbar, wenn ich den LayoutManager auf RecycleView setze. Bitte helfen Sie mir das Toast wird sichtbar, wenn ich auf lineares Layout klicke.Lineares Layout onclick Listener nicht mit recycle Ansicht arbeiten

Aktivitätscode:

public class PracticeActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_practice); 
     setLayoutViews(); 
    } 

    private void setLayoutViews(){ 

     // setting up messages list view 
     RecyclerView mMessagesView = (RecyclerView) findViewById(R.id.messages); 

     // if i uncomment below line Toast will not be visible. 
     //mMessagesView.setLayoutManager(new LinearLayoutManager(this)); 

     (findViewById(R.id.chat_section)).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Toast.makeText(PracticeActivity.this, " Chat section was clicked", Toast.LENGTH_SHORT).show(); 
      } 
     }); 
    } 

activity_practice.xml

<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="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/activity_main"> 
     <LinearLayout 
      android:id="@+id/chat_section" 
      android:layout_width="match_parent" 
      android:layout_height="320dp" 
      android:background="@color/chat_back_ground"> 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/messages" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:scrollbars="vertical" 
       android:scrollbarStyle="outsideOverlay"/> 
     </LinearLayout> 

     <TextView 
      android:layout_below="@id/chat_section" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Just text"/> 

</RelativeLayout> 
+0

itemView.setOnClickListener (this) identifiziert wird; Verwenden Sie in Ihrem Adapter viewHolder Klasse – vinoth12594

+0

Sie benötigen ViewHolder diesen Link http://StackOverflow.com/Questions/31790971/No-Toast-show-when-item-clicked-recyclerview –

Antwort