1
私はアンドロイドRecyclerViewを初めて使っていますが、RecyclerにEdittextフィールドを追加しようとしたときにエラーが発生します。これを行う方法が見つかりません。リサイクラーにEditTextを追加
public class MainActivity extends AppCompatActivity{
private RecyclerView mRecyclerView;
private CustomRecyclerAdapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private EditText mText;
private EditText mColor;
private List<Data> mData = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initializing views.
mText = (EditText) findViewById(R.id.textEt);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler);
// If the size of views will not change as the data changes.
mRecyclerView.setHasFixedSize(true);
// Setting the LayoutManager.
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
// Setting the adapter.
mAdapter = new CustomRecyclerAdapter();
mRecyclerView.setAdapter(mAdapter);
}
// Called when add button is clicked.
public void addItem(View view) {
// Add data locally to the list.
Data dataToAdd = new Data(
mText.getText().toString());
mData.add(dataToAdd);;
// Update adapter.
mAdapter.addItem(mData.size() - 1, dataToAdd);
}
}
CustomRecyclerAdapterが
データクラスが持っている}
package com.example.niroj.jsonandsqlite;
public class CustomRecyclerAdapter extends
RecyclerView.Adapter<RecyclerViewHolder> {
private List<Data> mData = Collections.emptyList();
public CustomRecyclerAdapter() {
// Pass context or other static stuff that will be needed.
}
public void updateList(List<Data> data) {
mData = data;
notifyDataSetChanged();
}
@Override
public int getItemCount() {
return mData.size();
}
@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
View itemView = inflater.inflate(R.layout.list_item, viewGroup, false);
return new RecyclerViewHolder(itemView);
}
@Override
public void onBindViewHolder(RecyclerViewHolder viewHolder, int position) {
viewHolder.title.setText(mData.get(position).text);
}
public void addItem(int position, Data data) {
mData.add(position, data);
notifyItemInserted(position);
}
public void removeItem(int position) {
mData.remove(position);
notifyItemRemoved(position);
}
です:誰でもこの問題と:)事前に感謝を解決してください:)これは私のmainactivityコードです単に含有物
public class Data {
public String text;
public Data(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}