[Android] mobile guard blacklist function (ListView combined with SQLite addition, deletion, and modification), androidsqlite

Source: Internet
Author: User
Tags phoneview

[Android] mobile guard blacklist function (ListView combined with SQLite addition, deletion, and modification), androidsqlite

On the modify page, add an Add button on the top horizontal bar, click to open a custom dialog box, enter the phone number and intercept mode, and save it to the database.

See this http://www.cnblogs.com/taoshihan/p/5370378.html in the Custom dialog box

 

Add record

Call the show () method of the Builder object to obtain the AlertDialog object.

Call the View. inflate () method to convert the layout file to a View object.

Call the findViewById () method of the View object to obtain the Button object for confirmation and cancellation.

Call the setOnClickListener () method of the Button object to set click events. Implement the OnClickListener interface in an anonymous internal class and override the onClick () method.

Call the dismiss () method of the AlertDialog object to close the dialog box.

Call the findViewById () method of the View object to obtain the values of each control for judgment and processing.

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

At this time, the ListView will not display the newly added record. You need to exit this Activity and rewrite it. We will notify the adapter to update data.

Call the add () method of the set List object to add a piece of data. Parameter: 0 (first), data

Call the yydatasetchanged () method of the ListAdapter object to notify data updates.

 

Delete record

In the entry layout file, place a small icon in the recycle bin on the right, center up and down, and right of the parent Control

 

Android clicks are similar to js clicks,

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

 

Get the delete Button object

Call the Button object to set click events

Gets the AlertDialog. Builder object and displays whether to delete the object.

Call the AlertDialog. Builder object and set the confirm and cancel buttons. Note that when you set the OnClickListener event, the package of the event 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 the yydatasetchanged () method of the ListAdapter object to notify data updates.

CallSmsSafeActivity. java

Package com. qingguow. mobilesafe; import java. util. hashMap; import java. util. list; import java. util. map; import android. app. activity; import android. app. alertDialog; import android. app. alertDialog. builder; import android. content. dialogInterface; import android. OS. bundle; import android. text. textUtils; import android. view. view; import android. view. view. onClickListener; import android. view. viewGroup; import androi D. widget. baseAdapter; import android. widget. button; import android. widget. checkBox; import android. widget. editText; import android. widget. imageView; import android. widget. listView; import android. widget. textView; import android. widget. toast; import com. qingguow. mobilesafe. db. ado. blackNumberAdo;/*** communication guard ** @ author taoshihan **/public class CallSmsSafeActivity extends Activity {private ListView listvie W; private List <Map <String, String> infos; private BlackNumberAdo dao; private MyAdapter myAdapter; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_call_sms_safe); listview = (ListView) findViewById (R. id. lv_blacknumber); myAdapter = new MyAdapter (); dao = new BlackNumberAdo (this); infos = dao. findAll (); listview. set Adapter (myAdapter); // Add 100 pieces of test data // Random random = new Random (); // for (int I = 1; I <= 100; I ++) {// ado. add (& quot; 18805419000 & quot; + I, String. valueOf (random. nextInt (3) + 1); //} class ViewHolder {public TextView phoneView; public TextView modeView; public ImageView iv_delete ;} private class MyAdapter extends BaseAdapter {@ Override public int getCount () {// TODO Auto-generated method stub return infos. siz E () ;}@ Override public View getView (final int position, View convertView, ViewGroup parent) {View view; ViewHolder holder = new ViewHolder (); if (convertView = null) {view = View. inflate (CallSmsSafeActivity. this, R. layout. list_call_sms_safe_item, null); holder. phoneView = (TextView) view. findViewById (R. id. TV _main_phone); holder. modeView = (TextView) view. findViewById (R. id. TV _block_mode); holder. iv_del Ete = (ImageView) view. findViewById (R. id. iv_delete); view. setTag (holder); System. out. println ("Creating a new View object" + position);} else {view = convertView; holder = (ViewHolder) view. getTag (); System. out. println ("use historical View object" + position);} holder. phoneView. setText (infos. get (position ). get ("phone"); switch (infos. get (position ). get ("mode") {case "1": holder. modeView. setText ("phone interception"); break; case "2": holder. modeView. s EtText ("SMS interception"); break; case "3": holder. modeView. setText ("All interceptions"); break; default: break;} // Delete the entry holder. iv_delete.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {AlertDialog. builder builder = new AlertDialog. builder (CallSmsSafeActivity. this); builder. setTitle ("warning"); builder. setMessage ("are you sure you want to delete it? "); Builder. setPositiveButton ("OK", new DialogInterface. onClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {infos. remove (position); myAdapter. notifyDataSetChanged (); dao. delete (infos. get (position ). get ("phone") ;}}); builder. setNegativeButton ("cancel", null); builder. show () ;}}); return view ;}@ Override public Object getItem (int position) {// TODO Auto-generated method stub return null ;} @ Override public long getItemId (int position) {// TODO Auto-generated method stub return 0 ;}} private EditText blackNumber; private CheckBox blockCall; private CheckBox blockSms; /*** add blacklist * @ param v */public void addCallSmsSafe (View v) {AlertDialog. builder builder = new AlertDialog. builder (this); View view = View. inflate (this, R. layout. dialog_add_safe_sms, null); builder. setView (view); final AlertDialog alertDialog = builder. show (); Button submit = (Button) view. findViewById (R. id. bt_submit); Button cancel = (Button) view. findViewById (R. id. bt_cancel); blackNumber = (EditText) view. findViewById (R. id. et_black_number); blockCall = (CheckBox) view. findViewById (R. id. cb_block_call); blockSms = (CheckBox) view. findViewById (R. id. cb_block_sms); submit. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {String phone = blackNumber. getText (). toString (). trim (); String mode = "3"; if (TextUtils. isEmpty (phone) {Toast. makeText (CallSmsSafeActivity. this, "Enter your mobile phone number", 0 ). show ();} if (blockCall. isChecked () & blockSms. isChecked () {// All interception mode = "3";} else if (blockCall. isChecked () {// call interception mode = "1";} else if (blockSms. isChecked () {// SMS interception mode = "2";} else {Toast. makeText (CallSmsSafeActivity. this, "Check interception mode", 0 ). show ();} dao. add (phone, mode); Map <String, String> info = new HashMap <String, String> (); info. put ("phone", phone); info. put ("mode", mode); infos. add (0, info); myAdapter. notifyDataSetChanged (); alertDialog. dismiss () ;}}); cancel. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {alertdiener. dismiss ();}});}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.