我在linearLayout中有Recycleview的问题。在下面的代码中,当我单击聊天部分时(线性布局),当我将LayoutManager设置为RecycleView时,Toast变得不可见。请帮助我,当我单击线性布局时,烤面包将可见。
活动代码:
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>
最佳答案
您可以按照本教程进行操作。接下来的过程是创建一个单独的itemtouchlistener类,从中识别选择
http://sapandiwakar.in/recycler-view-item-click-handler/