ListView refresh
<p>I have a question. I have a sqlite database in my project. I am select data in database and transfer the custom listview. My Custom ListView has got a delete button. When I press the button, my CostumListView class is delete this row. But Listview is the same. I want to make refresh listview after delete process. </p>

<p>This is my LAUNCHER Class (TaskList.java):</p>

<pre><code>package com.nano.tasklist;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class TaskList extends Activity {

ArrayList&lt;CategoryInfo&gt; CategoryList;

TaskListDatabase DatabaseActivity;

private CategoryAdapter CategoryAdapter = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_list);

    DatabaseActivity = new TaskListDatabase(this);

    CategoryInsert("School","21.02.2012","YES");
    CategoryInsert("House","21.02.2012","NO");
    CategoryInsert("Park","21.02.2012","YES");

    ListView lvCategories = (ListView) findViewById(R.id.lvCategories);

    CategoryList = new ArrayList&lt;CategoryInfo&gt;();

    CategoryAdapter = new CategoryAdapter(this, R.layout.category_row, CategoryList);
    lvCategories.setAdapter(this.CategoryAdapter);

    CategorySelect();
}

public void CategorySelect(){
    String[] Column = {"ID","Category","AddDate","Completed"};

    Cursor Result = null;

    try{
        SQLiteDatabase Database = DatabaseActivity.getReadableDatabase();

        Result = Database.query("Category", Column, null, null, null, null, null);

        startManagingCursor(Result);

        while(Result.moveToNext()){
            CategoryInfo Info = new CategoryInfo();

            CategoryList = new ArrayList&lt;CategoryInfo&gt;();

            Info.setID(Result.getString(Result.getColumnIndex("ID")));
            Info.setCategory(Result.getString(Result.getColumnIndex("Category")));
            Info.setAddDate(Result.getString(Result.getColumnIndex("AddDate")));
            Info.setCompleted(Result.getString(Result.getColumnIndex("Completed")));

            CategoryList.add(Info);

            if(CategoryList != null &amp;&amp; CategoryList.size() &gt; 0){
                CategoryAdapter.add(CategoryList.get(0));
                CategoryAdapter.notifyDataSetChanged();
            }
        }
    } catch (SQLiteException Error) {
        Toast.makeText(getApplicationContext(), "Error (CategorySelect) : " + Error.toString(), Toast.LENGTH_LONG).show();

        Result = null;
    }
}

public boolean CategoryInsert(String Category, String AddDate, String Completed){
    boolean Result;

    try{
        SQLiteDatabase Database = DatabaseActivity.getWritableDatabase();

        ContentValues Values = new ContentValues();

        Values.put("Category", Category);
        Values.put("AddDate", AddDate);
        Values.put("Completed", Completed);

        Database.insert("Category", null, Values);

        Result = true;
    } catch (SQLiteException Error) {
        Toast.makeText(getApplicationContext(), "Error (CategoryInsert) : " + Error.toString(), Toast.LENGTH_LONG).show();

        Result = false;
    }

    return Result;
}
</code></pre>

<p>This is my CustomListAdapter class (CategoryAdapter.java)</p>

<pre><code>package com.nano.tasklist;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

public class CategoryAdapter extends ArrayAdapter&lt;CategoryInfo&gt;{

private Context ActivityContext = null;
private ArrayList&lt;CategoryInfo&gt; Items = null;

TaskListDatabase DatabaseActivity;

public CategoryAdapter(Context Context, int textViewResourceId, ArrayList&lt;CategoryInfo&gt; Items){
    super(Context,textViewResourceId,Items);

    this.ActivityContext = Context;
    this.Items=Items;

    DatabaseActivity = new TaskListDatabase(Context);
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View MainView = convertView;

    if (MainView == null) {
        LayoutInflater Layout = (LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        MainView = Layout.inflate(R.layout.category_row, null);
    }

    final CategoryInfo Item = Items.get(position);

    if (Item != null) {

        final CheckBox cbCompleted = (CheckBox) MainView.findViewById(R.id.cbCategoryCompleted);
        final TextView tvCategoryName = (TextView) MainView.findViewById(R.id.tvCategoryName);
        final TextView tvAddDate = (TextView) MainView.findViewById(R.id.tvAddDate);
        final TextView tvDataValue = (TextView) MainView.findViewById(R.id.tvDataValue);
        final Button btnDeleteCategory = (Button) MainView.findViewById(R.id.btnDeleteCategory);

        tvCategoryName.setText(Item.getCategory());
        tvAddDate.setText(Item.getAddDate());
        tvDataValue.setText(Item.getDataValue());

        if(Item.getCompleted().equals("YES")){
            cbCompleted.setChecked(true);

            tvCategoryName.setEnabled(false);
            tvAddDate.setEnabled(false);
            tvDataValue.setEnabled(false);
        } else {
            cbCompleted.setChecked(false);

            tvCategoryName.setEnabled(true);
            tvAddDate.setEnabled(true);
            tvDataValue.setEnabled(true);
        }

        cbCompleted.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    CategoryUpdate(Item.getID(),"Completed","YES");

                    tvCategoryName.setEnabled(false);
                    tvAddDate.setEnabled(false);
                    tvDataValue.setEnabled(false);
                } else {
                    CategoryUpdate(Item.getID(),"Completed","NO");

                    tvCategoryName.setEnabled(true);
                    tvAddDate.setEnabled(true);
                    tvDataValue.setEnabled(true);
                }
            }
        });

        btnDeleteCategory.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                TaskList Process = new TaskList();
                Process.Delete(btnDeleteCategory, Item.getID());
            }
        });
    }

    return MainView;
}

public boolean CategoryUpdate(String ID, String Key, String Value){
    boolean Result;

    try{
        SQLiteDatabase Database = DatabaseActivity.getWritableDatabase();

        ContentValues Values = new ContentValues();

        Values.put(Key, Value);

        Database.update("Category", Values, "ID = " + ID, null);

        Result = true;
    } catch (SQLiteException Error) {
        Toast.makeText(ActivityContext, "Error (CategoryUpdate) : " + Error.toString(), Toast.LENGTH_LONG).show();

        Result = false;
    }

    return Result;
}

public void CategoryDelete(final String ID){
    try{

        AlertDialog.Builder Builder = new AlertDialog.Builder(ActivityContext);
        Builder.setMessage("If you delete this category, category's tasks will be deleted ! Do you want to delete this category ?")
                .setCancelable(false)
                .setPositiveButton("YES",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                SQLiteDatabase Database = DatabaseActivity.getWritableDatabase();

                                Database.delete("Category", "ID = " + ID, null);
                            }
                        })
                .setNegativeButton("NO",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.cancel();
                            }
                        });
        AlertDialog Alert = Builder.create();
        Alert.show();
    } catch (SQLiteException Error) {
        Toast.makeText(ActivityContext, "Error (CategoryDelete) : " + Error.toString(), Toast.LENGTH_LONG).show();
    }
}

}
</code></pre>

<p>This is my DatabaseClass (TaskListDatabase.java)</p>

<pre><code>package com.nano.tasklist;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class TaskListDatabase extends SQLiteOpenHelper{

private static final String DatabaseName = "TaskList";
private static final int DatabaseVersion = 1;
private static final String Category = "Category";
private static final String Tasks = "Tasks";

private static final String CreateCategoryTable = "CREATE TABLE " + Category + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, Category TEXT, AddDate TEXT, Completed TEXT);";
private static final String CreateTaskTable = "CREATE TABLE " + Tasks + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, Category TEXT, Task TEXT, AddDate TEXT, StartDate TEXT, FinishDate TEXT, Completed TEXT);";

public TaskListDatabase(Context Context){
    super(Context,DatabaseName,null,DatabaseVersion);
}

@Override
public void onCreate(SQLiteDatabase Database) {
    Database.execSQL(CreateCategoryTable);
    Database.execSQL(CreateTaskTable);
}

@Override
public void onUpgrade(SQLiteDatabase Database, int OldVersion, int NewVersion) {
    Database.execSQL("DROP TABLE IF EXISTS " + DatabaseName);
    onCreate(Database);
}
}
</code></pre>

<p>And this is my project : <a href="https://rapidshare.com/files/578334898/Task%20List.rar" rel="nofollow">https://rapidshare.com/files/578334898/Task%20List.rar</a></p>

<p>Please help me...</p>
