4.9 黑名单数据库的界面展示

调用dao层中查询数据库中数据的方法,将得到的数据装进集合中,显示在listView中

 

4.9 黑名单数据库的界面展示_第1张图片

 

 

 

public   class   CallSmsSafeActivity   extends   Activity {

       private   String   TAG =   "CallSmsSafeActivity" ;
       private   ListView   lv_callsms_safe ;
       private   BlackNumberDao   dao ;
       private   BlackNumberBean   blackNumberBean ;
       private   List   numberList   ;
       private   TextView    tv_number ;
       private   TextView    tv_mode ;
       private   ImageView iv_delete;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
            setContentView(R.layout. activity_callsms_safe);
            
             dao= new BlackNumberDao( this);
             numberList= dao.getNumberInfo();
            
            
             lv_callsms_safe=(ListView) findViewById(R.id.lv_callsms_safe );
             lv_callsms_safe.setAdapter( new MyAdapter());
            
            
      }
      
      
       /**
       * 创建适配器
       */
       public   class   MyAdapter    extends   BaseAdapter{

            
               @Override
               public   int   getCount() {
                  
                     return   numberList .size();
            }
            
            
               @Override
               public   View getView( int   position, View convertView, ViewGroup parent) {
                   View view = View. inflate(getApplicationContext(), R.layout. list_callsms_item , null   );
                     tv_number =(TextView) view.findViewById(R.id. tv_number   );
                     tv_mode =(TextView) view.findViewById(R.id.   tv_mode );
                     iv_delete =(ImageView) view.findViewById(R.id. iv_delete   );
                  
                     blackNumberBean   =   numberList .get(position);
                     tv_number .setText(   "号码:" + blackNumberBean   .getNumber());
                   String mode=   blackNumberBean .getMode();
                     if (   "1" .equals(mode)){
                           tv_mode .setText(   "电话拦截" );
                   }   else   if (   "2" .equals(mode)){
                           tv_mode .setText(   "短信拦截" );
                   }   else   if (   "3" .equals(mode)){
                           tv_mode .setText(   "全部拦截" );
                   }
                  
                     //给小垃圾桶图标设置删除事件
                     new   Thread(){
                        
                           public   void   run() {
                              
                                 iv_delete .setOnClickListener(   new   OnClickListener() {
                                    
                                    

                                       @Override
                                       public   void   onClick(View v) {
                                          
                                             dao .delete(   blackNumberBean .getNumber());
                                          
                                          Log. i( TAG   ,   "删除....."   );
                                    }
                              });
                         };
                        
                        
                   }.start();
                  
                  
                  
                     return   view;
            }

               @Override
               public   Object getItem(   int   position) {
                  
                     return   null ;
            }

               @Override
               public   long   getItemId(   int   position) {
                  
                     return   0;
            }

            
            
      }
      
      
      
}

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(手机安全卫士笔记)