[Android] mobile guard blacklist function (listview combined with SQLite)

Modify the interface, add an add button on the top bar, click to open a custom dialog box, enter the phone number and interception mode, and save it to the database

Customize the dialog box to see this article http://www.cnblogs.com/taoshihan/p/5370378.html

Add record

Call the show () method of the builder object to get the alertdialog object

Call the view. Inflate () method to convert the layout file into a view object

Call the findviewbyid() method of the view object to get the button object for confirmation and cancellation

Call setonclicklistener() method of button object, set click event, implement onclicklistener interface by anonymous inner class, and override onclick() method

You can close the dialog box by calling the dismiss () method of the alertdialog object

Call the findviewbyid() method of the view object to obtain the values of each control for judgment

Call the add () method of the previously defined Dao class blacknumberado object, and add a record to the database. Parameters: string phone number, string interception mode

At this time, the listview will not show the newly added record. You need to exit the activity and rewrite it. We will notify the adapter to update the data

Call the add () method of the collection list object to add a piece of data. Parameters: 0 (first), data

Call notifydatasetchanged() method of listadapter object to notify data update

Delete record

In the item layout file, a small icon of the trash can is placed on the right, centered up and down, and on the right of the parent control

The click event of Android system is very similar to that of JS,

Refer to this article: http://www.cnblogs.com/taoshihan/p/5438729.html

Get delete button object

Call the button object to set the click event

Get the alertdialog.builder object and display the dialog box to confirm deletion

Call the alertdialog.builder object and set the confirm button and cancel button. Note that when setting the click event onclicklistener, its package is dialoginterface.onclicklistener

Call the delete () method of the previously defined Dao class blacknumberado object. Parameter: string phone number

Call the remove () method of the collection list object to delete a piece of data. Parameter: int index

Call notifydatasetchanged() method of listadapter object to notify data update

CallSmsSafeActivity.java

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>