AdapterView不支持addView(View,LayoutParams)

时间:2018-05-03 21:22:54

标签: java android listview

这是我的MainActivity。我相信我有一个涉及列表适配器。我对如何解决我目前面临的具体问题感到困惑。

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

}

这是我的MainActivity的xml文件。我正在使用列表视图。

<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>

我真的很想知道我做错了什么,以及如何解决我想要做的事情。任何帮助将不胜感激。

0 个答案:

没有答案