Having difficulty constantly getting values from the editview and displaying it in the recyclerview one below the other. The code below uses a preset array of string to display the text which is simpler.
Mainactivity
Context context;
RecyclerView recyclerView;
RelativeLayout relativeLayout;
RecyclerView.Adapter recyclerViewAdapter;
RecyclerView.LayoutManager recylerViewLayoutManager;
String[] subjects =
{
"First Text",
"Second Text",
"Third Text",
"Fourth Text",
"Fifth Text",
"Sixth Text",
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
context = getApplicationContext();
relativeLayout = (RelativeLayout) findViewById(R.id.relativelayout1);
recyclerView = (RecyclerView) findViewById(R.id.recyclerview1);
recylerViewLayoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(recylerViewLayoutManager);
recyclerViewAdapter = new RecyclerViewAdapter(context, subjects);
recyclerView.setAdapter(recyclerViewAdapter);
}
Tried to this using the code below but it only updates the textview rather than keep posting new text one below the other
public void SendButton(View view){
// EditText
EditText editText = (EditText) findViewById(R.id.editText);
String editTextValue = editText.getText().toString();
// TextView
TextView textView = (TextView) findViewById(R.id.subject_textview);
textView.setText(editTextValue);
}
The adapter is for the preset array version
public RecyclerViewAdapter(Context context1,String[] SubjectValues1){
SubjectValues = SubjectValues1;
context = context1;
}
public static class ViewHolder extends RecyclerView.ViewHolder{
public TextView textView;
public ViewHolder(View v){
super(v);
textView = (TextView)v.findViewById(R.id.subject_textview);
}
}
@Override
public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
view1 = LayoutInflater.from(context).inflate(R.layout.recyclerview_items,parent,false);
viewHolder1 = new ViewHolder(view1);
return viewHolder1;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position){
holder.textView.setText(SubjectValues[position]);
}
@Override
public int getItemCount(){
return SubjectValues.length;
}
Been trying to get this to work for a while, but no luck, so would appreciate if someone helped me with this.