开发者

update textview in oncreate android

hi frnds i h开发者_如何转开发ave a button and a textview in a whole view,when i click the button then all contact are sved in csv file but i wnt when these contact are going to csv file it update text as "exporting 3 (this count is changingmeans 1 2 3 4 5....till total no of contacts) contcts " means text view is changing when i click button then how to do it

the code for getting total no. of contacts in phone is below...

      update:



                    @Override
        protected Boolean doInBackground(String... args) {
            int count;
            CSVWriter writer = null;
          try 
           {
            writer = new CSVWriter(new FileWriter(Environment.getExternalStorageDirectory().getAbsolutePath() + "/my_test_contact.csv"));
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
         }
        String displayName;
        String number;
        String emailid;
        long _id;

        String columns[] = new String[]{ ContactsContract.Contacts._ID,
                   ContactsContract.Contacts.DISPLAY_NAME };
        writer.writeColumnNames(); // Write column header
        Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
                   columns,                
                   null,               
                   null,               
                   ContactsContract.Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
        startManagingCursor(cursor);
         if(cursor.moveToFirst()) {  
           do {
               _id =      Long.parseLong(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));   
               displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).trim();
               number = getPrimaryNumber(_id);
               emailid=getEmailid(_id);


               writer.writeNext((displayName + "/" + number+ "/" +  emailid).split("/"));
           } 
           while(cursor.moveToNext());   
           csv_status = true;
       } else {
           csv_status = false;
       }
       try {
            if(writer != null)
                writer.close();
        } catch (IOException e)
        {
           Log.w("Test", e.toString());
        }
    return null;

     }


insert this code anywhere in activity

doInBackground :

Runnable myRun = new Runnable(){
    public void run(){
                        int count;
            CSVWriter writer = null;
          try 
           {
            writer = new CSVWriter(new FileWriter(Environment.getExternalStorageDirectory().getAbsolutePath() + "/my_test_contact.csv"));
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
         }
        String displayName;
        String number;
        String emailid;
        long _id;

        String columns[] = new String[]{ ContactsContract.Contacts._ID,
                   ContactsContract.Contacts.DISPLAY_NAME };
        writer.writeColumnNames(); // Write column header
        Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
                   columns,                
                   null,               
                   null,               
                   ContactsContract.Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
        startManagingCursor(cursor);
        int i = 1;
         if(cursor.moveToFirst()) {  
           do {
                publishProgress() //<<<< DO THIS
                               _id =      Long.parseLong(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));   
               displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).trim();
               number = getPrimaryNumber(_id);
               emailid=getEmailid(_id);


               writer.writeNext((displayName + "/" + number+ "/" +  emailid).split("/"));
           } 
           while(cursor.moveToNext());   
           csv_status = true;
       } else {
           csv_status = false;
       }
       try {
            if(writer != null)
                writer.close();
        } catch (IOException e)
        {
           Log.w("Test", e.toString());
        }

        ////////////////// end loop
    }
}

onProgressUpdate()

 runOnUiThread(new Runnable() {
            public void run(){
                TEXTVIEW.setText("GETTING contact"+integer);//update text! /// here
            }
        });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜