80,351
社区成员
发帖
与我相关
我的任务
分享
final Cursor cursor_phone= getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,null,null,null);
if(debug)
System.out.println("<log> cursor_phone set successfully");
BaseAdapter baseadapter = new BaseAdapter(){
/**
* 1. 这里加个if(debug) System.out.println("");会导致Syntax error on tokens,misplaced coonstructs
* 等莫名其妙的句法问题。不知何解。
* 2. getCount会在blockListV.setAdapter(baseadapter);之后重复回调约10次,不知为何。
* */t.println("<log> BaseAdapter getCount:"+
cursor_phone.getCount());
return cursor_phone.getCount();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
/**
* 3. getView也会在blockListV.setAdapter(baseadapter);之后重复回调约10次,不知为何。
*/
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
if(debug)
System.out.println("<log> BaseAdapter getView<"+position+">");
CheckBox adptCheckBox= new CheckBox(BlockCall.this);
if(cursor_phone.moveToPosition(position)){
String phone_number= cursor_phone.getString(cursor_phone.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
if(debug)
System.out.println("<log> cursor_phone.getnumber:"+phone_number
+"<"+position+">");
adptCheckBox.setText(phone_number);
if(inBlockList(phone_number)){
adptCheckBox.setChecked(true);
}
}
return adptCheckBox;
}
};
if(debug)
System.out.println("<log> just after BaseAdapter");
View view = getLayoutInflater().inflate(R.layout.list_view, null);
/**
* ListView获取实例时activity stop
* 问题在:layout的.xml文件把ListView弄错了
*/
final ListView blockListV= (ListView)view.findViewById(R.id.base_adpt_checkbox);
blockListV.setAdapter(baseadapter);
if(debug)
System.out.println("<log> block listview setadapter");
new AlertDialog.Builder(BlockCall.this).setTitle(R.string.contacts_list)
.setView(view).setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
/**
* 这里加个if(debug) System.out.println("");会导致Syntax error on tokens,misplaced coonstructs
* 等莫名其妙的句法问题。不知何解。
* */
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
if(debug)
System.out.println("<log> DialogInterface, blocklist OnClick");
blocklist.clear();
if(debug)
System.out.println("<log> blocklist cleared:"+blocklist+
";\n==blockListV.getCount():"+blockListV.getCount());
/**
* 4. 如果存在着空的电话号码,点击确认后,activity 会stop 掉。
* 现象是:getCount=16,但for结构里只执行到0-13就stop了,14和15未执行
* getChildAt(i)中的i与position错位,导致越界。但不知为何。
* 详细是i=0时,获取的是position=2的号码;i=13时,得到的是position=15的号码
*/
for(int i=0; i< blockListV.getCount(); i++){
CheckBox blockChild=new CheckBox(BlockCall.this);
blockChild=(CheckBox)blockListV.getChildAt(i);
if(debug)
System.out.println("<log> (blockChild["+i+"].getText():"+
(blockChild).getText().toString()+
" | isChecked:"+blockChild.isChecked());
if(blockChild.isChecked()){
blocklist.add((blockChild).getText().toString());
}
}
if(debug)
System.out.println("blocklist, after added:"+blocklist);
}
}).show();