View Full Version : ارتباط با اسامی مخاطبین در برنامه
  
tishab
دوشنبه 17 آذر 1393, 22:43 عصر
سلام
بعد از لمس یک button ، باید صفحه مربوط به دفترچه تلفن(اسامی مخاطبین) باز بشه و بعد از انتخاب یک مخاطب، اوون مخاطب رو مثلا بذاره در یک textView که در برنامه قرار داره..؟؟؟
ممنون میشم کسی کمکم کنه.. هر چی گشتم نبود..!
؟؟؟؟؟
:افسرده:
mosadatta
سه شنبه 18 آذر 1393, 07:14 صبح
سلام 
من همین مشکل را دارم تو نت هم چیزی پیدانکردم:متفکر:
tux-world
سه شنبه 18 آذر 1393, 09:54 صبح
سلام. تو نت چرا هست خیلی زیاده فقط باید بتونین درست سرچ کنید. برای این کار باید اول یه دیالگو داشته باشید که توش لیست ویو باشه و اون رو پر بکنید. ساختن دیالوگ با لیست ویو و اداپتر نباید چیز سختی براتون باشه ولی من سمپل و نمونه کدی رو که میتونین مخاطبها رو لیست کنید بهتون میدم. اگه مشکلی داشتید اطلاع بدید پ.خ بدید که متوجه بشم
    public void getContacts(ContentResolver cr){
        Cursor phones = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI , null,null,null, null);
        List<Person> personlst = new ArrayList<Person>();
        while (phones.moveToNext())
        {
            String id          = phones.getString(phones.getColumnIndex(ContactsCon tract.CommonDataKinds.Phone._ID));
            String name        = phones.getString(phones.getColumnIndex(ContactsCon tract.CommonDataKinds.Phone.DISPLAY_NAME));
            String phoneNumber = phones.getString(phones.getColumnIndex(ContactsCon tract.CommonDataKinds.Phone.NUMBER));
            Bitmap photo       = G.getContactPhoto ( phoneNumber, getContentResolver () );
            ContactListStructure item = new ContactListStructure();
            String phone_number = phoneNumber.replaceAll("\\s+","").trim ().replace("+98", "0");
            int check_mobile = phone_number.indexOf ( "09" );
            if( check_mobile != -1){
                item.id = Long.parseLong ( id );
                item.name = name;
                item.mobile = phone_number;
                item.photo = photo;
                item.checked = false;
                G.contact_item.add ( item );
                //personlst.add( new Person (item.name, item.mobile) );
            }
        }
        phones.close ();
    }
mosadatta
چهارشنبه 19 آذر 1393, 00:00 صبح
سلام ممنون منظورتون از دیالوگ چیست میشه مثال بزنید؟
tishab
چهارشنبه 19 آذر 1393, 01:20 صبح
ممنون از جواب شما....
چند تا خطا میده ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟
دیالوگ رو یه مثال بزنید فک کنم مشکل حل شه.. دیالوگ با غیر لیست ویو یه چیزایی میدونم ولی لیست ویو رو نه..!
Description    Resource    Path    Location    Type
ContactListStructure cannot be resolved to a type    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 63    Java Problem
ContactListStructure cannot be resolved to a type    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 63    Java Problem
ContactsCon cannot be resolved to a variable    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 58    Java Problem
ContactsCon cannot be resolved to a variable    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 59    Java Problem
ContactsCon cannot be resolved to a variable    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 60    Java Problem
G cannot be resolved    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 61    Java Problem
G cannot be resolved    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 72    Java Problem
Person cannot be resolved to a type    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 55    Java Problem
Person cannot be resolved to a type    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 55    Java Problem
Syntax error on token "tract", delete this token    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 58    Java Problem
Syntax error on token "tract", delete this token    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 59    Java Problem
Syntax error on token "tract", delete this token    SirsuspectSMSActivity.java    /SirsuspectSMS/src/sirsuspect/android/sms    line 60    Java Problem
tux-world
چهارشنبه 19 آذر 1393, 10:31 صبح
آسونترین ساخت دیالوگ سفارشی که میتونی ازش استفاده کنی کد زیر هستش:
            AlertDialog.Builder builder = new AlertDialog.Builder ( ActivityContactList.this );
            final View from_contacts_view = G.inflater.inflate ( R.layout.load_from_contacts, null );
            builder.setView ( from_contacts_view );
            final AlertDialog contacts_dialog = builder.create();
            contacts_dialog.getWindow().setBackgroundDrawable( new ColorDrawable (android.graphics.Color.TRANSPARENT));
            contacts_dialog.show();
فقط باید نام کلاس ActivityContactList رو به فایلی که توش استفاده میکنی و load_from_contacts رو به لای اوتی که طراحی کردی نسبت بدی. فقط نکته اینجاست که خیلی ها هم اشتباه میکنن این هستش که اگه کلیدی توش ساختید و میخوایید از اونها استفاده کنید نوع اتصالش فرق میکنه مثلا:
ListView    lstContent              = (ListView) contacts_dialog.findViewById ( R.id.lstContent );
نام دیالوگ contacts_dialog باید به همراه findViewById بیاد. ننوسید اندروید فکر میکنه که منظور شما لای اوت اصلیه و نال برمیگردونه و برنامه کرش میکنه
tishab
پنج شنبه 20 آذر 1393, 23:31 عصر
سلام. تو نت چرا هست خیلی زیاده فقط باید............
سلام... ممنون از شما...
کدها رو در رویداد یک کلید گذاشتم... 2 تا خطا سینتکس میده که هر کار کردم نتونستم رفع کنم؟؟؟؟؟
Syntax error on token "(", ; expected ----->>> line15
Syntax error on token ")", ; expected ----->>> line15
 (ContentResolver cr)، برای 2تا پرانتز خطا سینتکس میده..؟؟!
        //click button
        Button b = (Button) findViewById(R.id.button1);
        b.setOnClickListener(new OnClickListener() {            
            @Override
            public void onClick(View arg0) {
                      
                //
                AlertDialog.Builder builder = new AlertDialog.Builder ( SirsuspectSMSActivity.this );
                final View from_contacts_view = G.inflater.inflate ( R.layout.main, null );
                builder.setView ( from_contacts_view );
                final AlertDialog contacts_dialog = builder.create();
                contacts_dialog.getWindow().setBackgroundDrawable(  new ColorDrawable (android.graphics.Color.TRANSPARENT));
                contacts_dialog.show();
                //
                public void getContacts(ContentResolver cr){
                    Cursor phones = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI  , null,null,null, null);
                    List<Person> personlst = new ArrayList<Person>();
                    while (phones.moveToNext())
                    {
                        String id          = phones.getString(phones.getColumnIndex(ContactsCon .tract.CommonDataKinds.Phone._ID));
                        String name        = phones.getString(phones.getColumnIndex(ContactsCon .tract.CommonDataKinds.Phone.DISPLAY_NAME));
                        String phoneNumber = phones.getString(phones.getColumnIndex(ContactsCo. tract.CommonDataKinds.Phone.NUMBER));
                        Bitmap photo       = G.getContactPhoto ( phoneNumber, getContentResolver () );
                 
                        ContactListStructure item = new ContactListStructure();
                        String phone_number = phoneNumber.replaceAll("\\s+","").trim ().replace("+98", "0");
                        int check_mobile = phone_number.indexOf ( "09" );
                        if( check_mobile != -1){
                            item.id = Long.parseLong ( id );
                            item.name = name;
                            item.mobile = phone_number;
                            item.photo = photo;
                            item.checked = false;
                            G.contact_item.add ( item );
                           // personlst.add( new Person (item.name, item.mobile) );
                        }
                    }
                    phones.close ();
                }
                //
            }
        });
tux-world
پنج شنبه 20 آذر 1393, 23:48 عصر
...........
tux-world
پنج شنبه 20 آذر 1393, 23:52 عصر
خط ۱۵ رو متوجه نشدم. این کدی که گذاشتید کودوم خط میشه؟
//click button
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {            
    @Override
    public void onClick(View arg0) {
               
        //
        AlertDialog.Builder builder = new AlertDialog.Builder ( SirsuspectSMSActivity.this );
        final View from_contacts_view = G.inflater.inflate ( R.layout.main, null );
        builder.setView ( from_contacts_view );
        final AlertDialog contacts_dialog = builder.create();
        contacts_dialog.getWindow().setBackgroundDrawable(  new ColorDrawable (android.graphics.Color.TRANSPARENT));
        contacts_dialog.show();
        ContentResolver contentResolver=getContentResolver();
        getContacts(contentResolver);
        //
        public void getContacts(ContentResolver cr){
            Cursor phones = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI  , null,null,null, null);
            while (phones.moveToNext())
            {
                String id          = phones.getString(phones.getColumnIndex(ContactsCon  .tract.CommonDataKinds.Phone._ID));
                String name        = phones.getString(phones.getColumnIndex(ContactsCon  .tract.CommonDataKinds.Phone.DISPLAY_NAME));
                String phoneNumber = phones.getString(phones.getColumnIndex(ContactsCo.  tract.CommonDataKinds.Phone.NUMBER));
                Bitmap photo       = G.getContactPhoto ( phoneNumber, getContentResolver () );
          
                ContactListStructure item = new ContactListStructure();
                    item.id = Long.parseLong ( id );
                    item.name = name;
                    item.mobile = phone_number;
                    item.photo = photo;
                    item.checked = false;
                    G.contact_item.add ( item );
            }
            phones.close ();
        }
        //
    }
});        
کلاس کانتکت :
public class ContactListStructure implements Serializable {
    public Long     id;
    public String   name;
    public String   mobile;
    public Bitmap   photo;
    public Boolean  checked;
    public ContactListStructure (Long id, String name, String mobile, Bitmap photo, Boolean checked) {
        this.id = id;
        this.name = name;
        this.mobile = mobile;
        this.photo = photo;
        this.checked = checked;
    }
    public ContactListStructure () {}
    public Long getId () {
        return id;
    }
    public void setId (Long id) {
        this.id = id;
    }
    public String getName () {
        return name;
    }
    public void setName (String name) {
        this.name = name;
    }
    public String getMobile () {
        return mobile;
    }
    public void setMobile (String mobile) {
        this.mobile = mobile;
    }
    public Bitmap getPhoto () {
        return photo;
    }
    public void setPhoto (Bitmap photo) {
        this.photo = photo;
    }
    public Boolean getChecked () {
        return checked;
    }
    public void setChecked (Boolean checked) {
        this.checked = checked;
    }
}
tishab
جمعه 21 آذر 1393, 00:45 صبح
خط ۱۵ رو متوجه نشدم. این کدی که گذاشتید کودوم خط میشه؟
منظورم همون خط 15 است که در اینجا گذاشتم..
 publicvoidgetContacts(ContentResolver cr){
tishab
جمعه 21 آذر 1393, 00:49 صبح
کدی که دوباره گذاشتین(کد قبل از کلاس کانتکت) ،کد رو تغییر دادید بعضی جاهاش رو..؟؟!!؟؟ :متفکر:
در زمانی که کلاس میخام اضافه کنم، (Superclass) یا نوع کلاس باید چی باشه؟؟
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.