将文本字段编辑为回收站视图

时间:2016-09-21 09:49:17

标签: android android-recyclerview recycler-adapter

我正在尝试将editText字段发送到下一个recycler list的{​​{1}},但我无法获取它。问题是我无法看到列表中添加的activity字段列表。例如:当我从editText添加水银并点击保存editText时,我可以看到button中的水银。但是,当我写下金星并点击保存按钮时,水银消失并出现金星。

这是我的回收商recyclerView

adapter

这是public RecyclerViewAdapter(Context context, ArrayList<String> nameList){ layoutInflater = LayoutInflater.from(context); itemsName = nameList; } @Override public RecyclerViewAdapter.ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = layoutInflater.inflate(R.layout.text_view,parent, false); return new ItemHolder(itemView, this); } @Override public void onBindViewHolder(RecyclerViewAdapter.ItemHolder holder, int position) { holder.setItemName(itemsName.get(position)); } @Override public int getItemCount() { return (null != itemsName ? itemsName.size() : 0); } public void setOnItemClickListener(OnItemClickListener listener){ onItemClickListener = listener; } public OnItemClickListener getOnItemClickListener(){ return onItemClickListener; } public interface OnItemClickListener{ public void onItemClick(ItemHolder item, int position); } public static class ItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ private RecyclerViewAdapter parent; TextView textItemName; public ItemHolder(View itemView, RecyclerViewAdapter parent) { super(itemView); itemView.setOnClickListener(this); this.parent = parent; textItemName = (TextView) itemView.findViewById(R.id.herecomes); } public void setItemName(CharSequence name){ textItemName.setText(name); } public CharSequence getItemName(){ return textItemName.getText(); } @Override public void onClick(View v) { final OnItemClickListener listener = parent.getOnItemClickListener(); if(listener != null){ listener.onItemClick(this, getPosition()); } } }} activity字段,我点击保存editText后发送字段值。

button

这是包含 public class MyEditor extends AppCompatActivity { EditText textIn,txtHeading; Button buttonAdd,btnsave; ArrayList<String> nameList = new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.editor); txtHeading = (EditText)findViewById(R.id.heading); buttonAdd = (Button)findViewById(R.id.add); btnsave =(Button) findViewById(R.id.btn_save); btnsave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String newName = txtHeading.getText().toString().trim(); if(newName.length()!=0) { nameList.add(newName); txtHeading.setText(""); Intent intent = new Intent(getApplicationContext(), BuilderPage.class); intent.putStringArrayListExtra("key", nameList); nameList.add(newName); int listsize = nameList.size(); for (int i = 0; i < listsize; i++) { Log.i("Lists are", nameList.get(i)); Log.i("Lists are", "The size of array is:" + nameList.size()); } startActivity(intent); Toast.makeText(MyEditor .this, "You added" + newName.toUpperCase() + "in your view", Toast.LENGTH_LONG).show(); } } }); }}

的类
recyclerView

0 个答案:

没有答案