在机器人的OnCreate

在机器人的OnCreate

本文介绍了在机器人的OnCreate TextView的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好frnds我,我有一个按钮,并在一个整体视图一个TextView,当我点击按钮,然后所有的接触都在csv文件sved但我Wnt信号时,这些接触将要CSV文件,其更新的文字为出口3(此计数为changingmeans 1 2 3 4 5 ....直到接触的总量不)contcts是指当我点击按钮后,该怎么办呢文本视图改变

在code为获得总没有。在手机通讯录的是低于...

 更新:                    @覆盖
        保护布尔doInBackground(字符串参数... args){
            诠释计数;
            CSVWriter作家=无效;
          尝试
           {
            作家=新CSVWriter(新的FileWriter(Environment.getExternalStorageDirectory()getAbsolutePath()+/my_test_contact.csv)。);
        }赶上(IOException异常E1){
            // TODO自动生成catch块
            e1.printStackTrace();
         }
        字符串显示名;
        串号;
        串EMAILID;
        长_id;        字符串列[] =新的String [] {ContactsContract.Contacts._ID,
                   ContactsContract.Contacts.DISPLAY_NAME};
        writer.writeColumnNames(); //写列标题
        光标光标= getContentResolver()查询(ContactsContract.Contacts.CONTENT_URI,
                   列,
                   空值,
                   空值,
                   ContactsContract.Data.DISPLAY_NAME +分页中局部ASC);
        startManagingCursor(光标);
         如果(cursor.moveToFirst()){
           做{
               _id =的Long.parseLong(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));
               显示名= cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))修剪()。
               数= getPrimaryNumber(_id);
               EMAILID = getEmailid(_id);
               writer.writeNext((显示名+/+数字+/+ EMAILID).split(/));
           }
           而(cursor.moveToNext());
           csv_status = TRUE;
       }其他{
           csv_status = FALSE;
       }
       尝试{
            如果(作家!= NULL)
                writer.close();
        }赶上(IOException异常E)
        {
           Log.w(测试,e.toString());
        }
    返回null;     }


解决方案

在活动的任何位置插入此code

doInBackground:

 的Runnable myRun =新的Runnable(){
    公共无效的run(){
                        诠释计数;
            CSVWriter作家=无效;
          尝试
           {
            作家=新CSVWriter(新的FileWriter(Environment.getExternalStorageDirectory()getAbsolutePath()+/my_test_contact.csv)。);
        }赶上(IOException异常E1){
            // TODO自动生成catch块
            e1.printStackTrace();
         }
        字符串显示名;
        串号;
        串EMAILID;
        长_id;        字符串列[] =新的String [] {ContactsContract.Contacts._ID,
                   ContactsContract.Contacts.DISPLAY_NAME};
        writer.writeColumnNames(); //写列标题
        光标光标= getContentResolver()查询(ContactsContract.Contacts.CONTENT_URI,
                   列,
                   空值,
                   空值,
                   ContactsContract.Data.DISPLAY_NAME +分页中局部ASC);
        startManagingCursor(光标);
        INT I = 1;
         如果(cursor.moveToFirst()){
           做{
                publishProgress()//<<<<做这个
                               _id =的Long.parseLong(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));
               显示名= cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))修剪()。
               数= getPrimaryNumber(_id);
               EMAILID = getEmailid(_id);
               writer.writeNext((显示名+/+数字+/+ EMAILID).split(/));
           }
           而(cursor.moveToNext());
           csv_status = TRUE;
       }其他{
           csv_status = FALSE;
       }
       尝试{
            如果(作家!= NULL)
                writer.close();
        }赶上(IOException异常E)
        {
           Log.w(测试,e.toString());
        }        //////////////////结束循环
    }
}

onProgressUpdate()

  runOnUiThread(新的Runnable(){
            公共无效的run(){
                TEXTVIEW.setText(抵达接触+整数); //更新的文字! /// 这里
            }
        });

hi frnds i have 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
            }
        });

这篇关于在机器人的OnCreate TextView的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 14:34