0

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();

}
slgnalin
  • 25
  • 6
  • What's in R.layout.row? where are you populating the views of your layout? – Nicola Gallazzi Sep 17 '18 at 15:31
  • R.layout.row is the xml file where I designed one row of the ListView elements – slgnalin Sep 17 '18 at 15:42
  • Actually, I think you should implement a custom adapter. Documentation can help you but I would use a RecyclerView instead of a List view https://developer.android.com/guide/topics/ui/layout/recyclerview. If you are a little bored about ViewHolder pattern you can use this simple library https://github.com/gotev/recycler-adapter to get rid of the boilerplate – Nicola Gallazzi Sep 17 '18 at 15:47

0 Answers0