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;
}
}
}