Joke Collection Website - Blessing messages - Android4.4 can't read ListView with AsyncQueryHandler SMS.
Android4.4 can't read ListView with AsyncQueryHandler SMS.
private static final String NAME = " NAME ",NUMBER = "number ",SORT _ KEY = " sort _ key
Private List & lt Content Value & gtlistData
Private AsyncQueryHandler asyncQuery
Private ListView personnel list;
Dedicated BaseAdapter adapter;
@ Overlay
public void on create(Bundle saved instancestate){
super . oncreate(savedInstanceState);
setContentView(r . layout . main);
person list =(ListView)findViewById(r . id . list _ view);
async query = new MyAsyncQueryHandler(getContentResolver());
//Read contact information asynchronously.
asyncQueryContact();
}
Private void asyncQueryContact() {
// TODO automatically generated method stub
uri uri = uri . parse(" content://com . Android . contacts/data/phones ");
String[] projection = { "_id "," display_name "," data 1 "," sort _ key " };
asyncQuery.startQuery(0,null,uri,projection,null,null," sort _ key COLLATE LOCALIZED ASC ");
}
The private class MyAsyncQueryHandler extends AsyncQueryHandler {
Public myaasyncqueryhandler (content resolver Cr) {
Super (Cr);
}
@ Overlay
Protected void onQueryComplete(int tag, object cookie, cursor) (
If (cursor! = null & amp& ampcursor . get count()& gt; 0) {
ListData = new ArrayList & lt Content Value & gt ();
//cursor . move to first();
for(int I = 0; Me & ltcursor. getcount (); i++) {
content values cv = new content values();
cursor . move to position(I);
string name = cursor . getstring( 1);
string number = cursor . getstring(2);
string sort key = cursor . getstring(3);
if(number . starts with("+86 "){
Cv.put (name, name);
//Process (+86)
cv.put(NUMBER,NUMBER . substring(3));
cv.put(SORT_KEY,SORT KEY);
} Otherwise {
Cv.put (name, name);
Cv.put (number, number);
cv.put(SORT_KEY,SORT KEY);
}
list data . add(cv);
}
if(list data . size()& gt; 0) {
setAdapter(list data);
}
Cursor.close ();
}
}
}
Private void set adapter (list <: Content value & gt list data) (
adapter = new ListAdapter(this,list data);
PersonList.setAdapter (adapter);
}
Private class ListAdapter extends BaseAdapter {
Private layout inflator;
Private list & lt content value & gt list;
Public ListAdapter(Context, List & lt content value & gt list) {
This.importer = layoutimporter.from (context);
this.list = list
}
@ Overlay
public int getCount() {
Returns list. size ();
}
@ Overlay
Common object getitem (intposition) (
Returns list. get (position);
}
@ Overlay
public long getItemId(int position){
Return position;
}
@ Overlay
Public view getView(int position, View convertView, view group parent) (
ViewHolder holder holder;
if (convertView == null) {
convert view = inflater . inflate(r . layout . list _ item,null);
holder = new view holder();
holder . name =(TextView)convert view . findviewbyid(r . id . name);
holder . number =(TextView)convert view . findviewbyid(r . id . number);
convert view . settag(holder);
} Otherwise {
holder =(view holder)convert view . gettag();
}
content values cv = list . get(position);
holder . NAME . settext(cv . getasstring(NAME));
holder . NUMBER . settext(cv . getasstring(NUMBER));
Return to convertView
}
Private class viewer {
TextView name;
Text view number;
}
}
}
I can't say a word or two.
Why don't you come and talk to our group? Someone here knows this function.
Let them explain to you how to look at my new media. ....
- Previous article:What is the difference between telephone banking and mobile banking?
- Next article:Bless your friends when Grain Rain arrives.
- Related articles
- Which is better, Kawasaki ZRX4 or YAMAHAXJR4?
- How to apply for a refund on Jingdong Mall
- Birthday wishes to friends are short.
- Mobile phone can't send text messages. What is the number of Dongguan Unicom SMS Center?
- Notice on safe use of electricity in office buildings
- Has Wang Qingcan, vice principal of Zhengzhou No. 4 Middle School, retired?
- Is there much overdue collection of credit wallet?
- How to open Alipay and what are the steps to open Alipay?
- A novel named ex-husband. What is the name of the novel that she sent to her best friend by mistake and sent to her husband by mistake?
- Excellent template for the implementation plan of vocational education activity week in 2022