0

This is my MainActivity. I getting an involving a list adapter I believe. I'm just confused on how I go about to fix the specific problem I am currently facing.

public class MainActivity extends ListActivity {

private Todo todo;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Creating todo object
    todo = new Todo(this);

    //Set the list adapter to get list from Todo
    //I believe this is one fo the places that is causing the error
    setListAdapter(new ListAdd(this, todo.getTodo()));

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    //TODO item that was clicked
    TodoInfo todoInfo = (TodoInfo)getListAdapter().getItem(position);

    //Delete todo object from the database
    todo.deleteTodo(todoInfo.getId());

    //Set the list adapter and get Todos list from todo
    setListAdapter(new ListAdd(this, todo.getTodo()));

    //Display a message
    Toast.makeText(getApplicationContext(), "Deleted the item!", Toast.LENGTH_SHORT).show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    Intent intent = new Intent(this, Todo.class);

    startActivity(intent);

    this.finish();

    todo.close();

    return super.onOptionsItemSelected(item);
}

}

This is my xml file for my MainActivity. I'm using a List View.

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="40dp">

 <TextView
        android:id="@+id/todoText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Text Goes Here"/>

    </ListView>

I Just really want to know exactly what I'm doing wrong and how can I fix it for what I am trying to do. Any help will be greatly appreciated.

Suleyman
  • 2,765
  • 2
  • 18
  • 31
THE ONE
  • 1
  • 8
  • Make sure you [edit] the question and put the error details in it. It won't be seen in the title. However, in this case this question has come up a lot, and a simple search for the error will get you your explanation. e.g.: https://stackoverflow.com/q/4576219/1531971 among others. –  May 03 '18 at 21:24
  • ListView is not performant and is deprecated. Use RecyclerView instead. – Michael Lukin May 03 '18 at 21:28
  • You cannot have any other ``s inside a `` in your layout. If `todoText` is meant to be the `` for each list item, then it needs to go in a separate layout file, and that's the `R.layout` you would inflate in your `Adapter`. – Mike M. May 05 '18 at 02:33

0 Answers0