Reputation: 25
I am trying to make a ToDo List app for android and I have three EditText views in which the user can write the task title and the task content. I want to send both of these from the EditText views in the ListView I have.
My onCreate method:
ArrayAdapter<String> mAdapter;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
FloatingActionButton faButton = (FloatingActionButton) findViewById(R.id.fab); //Find Floatin Action Button
// Waits for you to click the button
faButton.setOnClickListener(new View.OnClickListener() { //Set onClickListener on fab
@Override
public void onClick(View view) { //onClick method
addNotification(); //adds notification
listView.setAdapter(mAdapter); //sets the adapter
addToDoElement(null); //adds task to taskList
}
});
loadTaskList();
dbHelper = new DBHelper(this);
listView = (ListView)findViewById(R.id.lstTask);
listView = (ListView) findViewById(R.id.lstTask);
taskList = new ArrayList<>();
mAdapter = new ArrayAdapter<String>(this, R.layout.row, R.id.task_title, taskList);
listView.setAdapter(mAdapter);
}
The class that transfers the EditText text to the ListView:
ArrayList<String> taskList;
public void addToDoElement(View view) {
//Gets TITLE text from EditText and sets it as title
EditText mEdit = (EditText)findViewById(R.id.title);
Log.v("EditText", mEdit.getText().toString());
//Gets CONTENT text from EditText and sets it as content
EditText mEdit2 = (EditText)findViewById(R.id.content);
Log.v("EditText", mEdit2.getText().toString());
taskList.add(mEdit.getText().toString());
mEdit.setText("");
mAdapter.notifyDataSetChanged();
}
Upvotes: 0
Views: 110