Android刷新列表视图问题。

时间:2014-02-04 15:45:43

标签: android sqlite listview

我遇到了listview刷新的问题,我有一个可以加载的刷新功能,当我点击一个与之关联的按钮时。在向SQLite数据库添加信息并调用刷新函数后,它不会刷新。

    //Add item to order Table.
    public void addItemToOrder()
{
    itemNumberValue = qoItemNumber.getText().toString();
    orderQtyValue = qoOrderQty.getText().toString();
    itemDescValue = qoItemDesc.getText().toString();


    Intent searchItem = new Intent(getApplicationContext(),inputOrder.class);

    searchItem.putExtra("itemnumb", itemNumberValue);
    searchItem.putExtra("orderqty", orderQtyValue);
    searchItem.putExtra("qoitemdesc", itemDescValue);

    startActivity(searchItem);
    fillData();

}

    //Load item table to listview
    public void fillData() {
        // Get all of the rows from the database and create the item list
        mNotesCursor = mDbHelper.fetchAllOrders();
        startManagingCursor(mNotesCursor);



        // Create an array to specify the fields we want to display in the list (only TITLE)
        String[] from = new String[]{HDWDBHelper.KEY_ITEMNUM, HDWDBHelper.KEY_DESC, HDWDBHelper.KEY_QTY};

        // and an array of the fields we want to bind those fields to (in this case just text1)
        //int[] to = new int[]{R.id.text1};
        int[] to = new int[]{R.id.tvItemNum, R.id.tvItemDesc, R.id.tvQty};

        // Now create a simple cursor adapter and set it to display
        SimpleCursorAdapter notes =
                new SimpleCursorAdapter(this, R.layout.itemlist, mNotesCursor, from, to);


        notes.notifyDataSetChanged();
        setListAdapter(notes);
        notes.notifyDataSetChanged();
        Log.v("fillData", "In fillData");
    }

当我在onCreate()或按钮点击时调用fillData()时,它可以工作但是当我在addItemToOrder()函数中调用它时,没有任何反应。列表视图仍然显示列出的先前项目,直到我单击刷新按钮,然后它显示添加的新项目。

0 个答案:

没有答案