在oncreate android中更新textview

时间:2011-08-01 12:24:32

标签: android

嗨frnds我在整个视图中有一个按钮和一个textview,当我点击按钮然后所有联系人都在csv文件中删除了但是当这些联系人转到csv文件时它会更新文本为“export 3”(这个count is changingmeans 1 2 3 4 5 ....直到没有联系人)收缩“意味着文本视图正在改变,当我点击按钮然后该怎么做

获得总数的代码。电话中的联系人信息如下......

      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;

     }

1 个答案:

答案 0 :(得分:1)

将此代码插入活动

中的任意位置

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