Привет всем У меня есть два recyclerviews, из которых один находится в нижний лист. Верхняя часть работает нормально, но нижняя не показывает ничего. и в лог-кате не отображается ошибка. Это мой MainActivity.ClassTwo Recycliewiew one in Bottom Sheet Layout, не отображающий данные в макете координаты
import android.content.ContentValues;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.example.app.adapter.CardViewDataAdapter;
import com.example.app.adapter.UserListAdapter;
import com.example.app.beans.ItemsBean;
import com.example.app.classes.UserSelectedItems;
import com.example.app.database.DBHelper;
import com.example.app.utils.CommonUtilities;
import com.example.app.utils.Constants;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
private RecyclerView mRecyclerView, selected_recyclerview;
private RecyclerView.Adapter mAdapter;
UserListAdapter adapter;
private RecyclerView.LayoutManager mLayoutManager;
List<String> selected_items= new ArrayList<>();
View bottomSheet;
BottomSheetBehavior behavior;
private List<ItemsBean> itemList;
String[] items= new String[]{"Sugar", "Tea", "Coffee", "Milk", "Bread", "Butter", "Jeera", "Egg", "Buiscuit", "JAM", "Maggi",
"Wheat", "Lentils", "Shampoo","Soap", "oil", "Hair Spray", "Coconut", "Cream", "Curd", "Cheese"};
String[] item_ids= new String[]{"101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114",
"115", "116", "117", "118", "119", "120", "121"};
private Button btnSelection;
DBHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
btnSelection = (Button) findViewById(R.id.btnShow);
selected_recyclerview= (RecyclerView)findViewById(R.id.recyclerView);
bottomSheet = findViewById(R.id.bottom_sheet);
behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
}
});
dbHelper= CommonUtilities.getDBObject(this);
itemList = new ArrayList<>();
for (int i = 0; i < items.length; i++) {
ItemsBean bean= new ItemsBean();
bean.setItemId(item_ids[i]);
bean.setItemName(items[i]);
bean.setItemStatus(1);
itemList.add(bean);
ContentValues values= new ContentValues();
values.put(Constants.ITEM_ID,item_ids[i]);
values.put(Constants.ITEM_NAME, items[i]);
values.put(Constants.ITEM_STATUS,1);
dbHelper.insertContentVals(Constants.MASTER_ITEM_TABLE, values);
}
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Grocery List");
}
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// create an Object for Adapter
mAdapter = new CardViewDataAdapter(itemList);
// set the adapter object to the Recyclerview
mRecyclerView.setAdapter(mAdapter);
btnSelection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data = "";
List<ItemsBean> stList = ((CardViewDataAdapter) mAdapter)
.getStudentist();
for (int i = 0; i < stList.size(); i++) {
ItemsBean singleStudent = stList.get(i);
if (singleStudent.isSelected() == true) {
selected_items.add(singleStudent.getItemName().toString());
data = data + "\n" + singleStudent.getItemName().toString();
/*
* Toast.makeText(CardViewActivity.this, " " +
* singleStudent.getName() + " " +
* singleStudent.getEmailId() + " " +
* singleStudent.isSelected(),
* Toast.LENGTH_SHORT).show();
*/
}
}
selected_recyclerview.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
selected_recyclerview.setLayoutManager(linearLayoutManager);
adapter = new UserListAdapter(MainActivity.this, selected_items);
selected_recyclerview.setAdapter(adapter);
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
Log.e("size", "size=" + selected_items.size());
/*Intent i= new Intent(MainActivity.this, UserSelectedItems.class);
i.putStringArrayListExtra("selected", (ArrayList<String>) selected_items);
Toast.makeText(MainActivity.this,
"Selected Students: \n" + data, Toast.LENGTH_LONG)
.show();
startActivity(i);*/
}
});
}
}
Вот мой XML файл
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#a3b1ef"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:scrollbars="vertical" />
<Button
android:id="@+id/btnShow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#00796B"
android:text="Show Selected"
android:textColor="@color/TextPrimaryColor" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:gravity="center"
android:orientation="vertical"
app:layout_behavior="@string/bottom_sheet_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:background="#fff" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/proceed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="10dp"
android:src="@android:drawable/arrow_up_float" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Вот user_list_row
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="5dp"
android:gravity="center">
<TextView
android:id="@+id/item_name"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="@color/col444"
android:text="Sugar"/>
<Spinner
android:id="@+id/brand"
android:layout_width="0dp"
android:layout_weight="0.3"
android:layout_height="wrap_content"
android:textColor="@color/col444"
android:layout_toRightOf="@id/item_name"
></Spinner>
<Spinner
android:id="@+id/unit"
android:layout_width="0dp"
android:textColor="@color/col444"
android:layout_weight="0.3"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/brand"
></Spinner>
<EditText
android:id="@+id/quantity"
android:layout_width="0dp"
android:layout_weight="0.2"
android:hint="Qty."
android:textColor="@color/col444"
android:layout_height="wrap_content" />
</LinearLayout>
Вот UserItem адаптер
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import com.example.app.R;
import com.example.app.beans.SelectedBean;
import com.example.app.classes.UserSelectedItems;
import java.util.List;
/**
* Created by me on 9/22/2016.
*/
public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.UserViewHolder>{
Context context;
List<String> data;
String[] brands= new String[]{
"Select Brand","Brand One", "Brand Two", "Brand Three", "Brand Four"
};
String[] units= new String[]{"Select Unit", "Kg", "Gms", "Lbs", "Pieces"};
public UserListAdapter(Context context, List<String> data){
this.context= context;
this.data= data;
}
@Override
public UserViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.user_list_row, null);
// create ViewHolder
UserViewHolder viewHolder = new UserViewHolder(itemLayoutView);
return viewHolder;
}
@Override
public void onBindViewHolder(UserViewHolder holder, int position) {
holder.itemName.setText(data.get(position));
ArrayAdapter<String> adapter= new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, brands);
holder.brand.setAdapter(adapter);
ArrayAdapter<String> madapter= new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, units);
holder.unit.setAdapter(madapter);
/* holder.unit.setSelection(0);
holder.brand.setSelection(0);*/
final SelectedBean bean= new SelectedBean();
bean.setItemName(data.get(position));
holder.unit.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position!=0){
bean.setUnitName(units[position]);
bean.setUnitSelectedPos(position);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
/* if(DetailActivity.list!=null && DetailActivity.list.size()>0) {
holder.brand.setSelection(DetailActivity.list.get(position).getBrandSelectedPos());
holder.unit.setSelection(DetailActivity.list.get(position).getUnitSelectedPos());
}*/
}
});
holder.brand.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
bean.setBrandName(brands[position]);
bean.setBrandSelectedPos(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
holder.quantity.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
bean.setQuantity(s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
holder.brand.setSelection(bean.getBrandSelectedPos());
holder.unit.setSelection(bean.getUnitSelectedPos());
Log.e("size", "= "+ UserSelectedItems.list.size());
UserSelectedItems.list.add(bean);
}
@Override
public int getItemCount() {
return data.size();
}
public class UserViewHolder extends RecyclerView.ViewHolder{
TextView itemName;
EditText quantity;
Spinner brand, unit;
public UserViewHolder(View itemView) {
super(itemView);
itemName= (TextView)itemView.findViewById(R.id.item_name);
quantity= (EditText) itemView.findViewById(R.id.quantity);
brand= (Spinner)itemView.findViewById(R.id.brand);
unit= (Spinner)itemView.findViewById(R.id.unit);
}
}
}
Пожалуйста, дайте мне знать, что я должен сделать, чтобы показать данные в recyclerview в нижней макете листа. На нижней кнопке находится кнопка, по которой нижний лист расширяется, как показано ниже. Заранее спасибо.
пожалуйста, покажите UserListAdapter и raw_list_item XML –
@AlexChengalan Его сделал, пожалуйста, проверьте –