Multi-Contact Selection

Put your problem here if it does not fit any of the other categories.

Multi-Contact Selection

Postby Skullmonkey » Thu Jan 05, 2012 5:19 am

I'm making a program where it will send a text message to a select group of people at a push of a button for fire departments. Right now, all of the numbers are hard coded in so if they want to add or remove someone from the list, they have to go through me and I have to send them the program every time.

I want to make it so that a contact list will come up and they can check/uncheck the people they want to send it to. I have searched for hours on end and can not find a clear (or even a rough for that matter) tutorial on how to accomplish this. There are a ton on how to select a single user, but none on how to select multiple people.

Here is what I need:
-Contact list that will select multiple people
-Selection sticks after closing the program, restarting phone, etc.

Other then that, the rest of the program is coded and working.

Thanks in advance for any help given.
Matt
Skullmonkey
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jan 05, 2012 4:48 am

Top

Re: Multi-Contact Selection

Postby Phyll » Thu Jan 05, 2012 12:56 pm

Hi Skullmonkey,

If you are using listview then you can add a checkbox to each item in the list and use that checkbox to determine if it is selected or not. Look at this example:

http://www.androidpeople.com/android-li ... ce-example

Here is a spinner example:

http://stackoverflow.com/questions/5015 ... ple-choice

I just noticed there was another part to that. You would then want to keep this in the preferences or a data base file so that it would be stored for the next time and actually there might be a way to do it all in the preferences with the preference editor if you treat this list of names like booleans. However you will be endlessly maintaining the list I guess unless you make a way for the user to edit the list also. That kind of suggests data base I think.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Multi-Contact Selection

Postby Skullmonkey » Thu Jan 05, 2012 2:52 pm

I have looked into the listview which seems to be how most, if not all, of the single selection works. The problem is that I have only seen it coded in with the script and not calling an xml to populate the list but is populated within the script (ex, the example given).

I am relatively new to java. I was only able to get what I have done now through examples and modifying them to my use.
Skullmonkey
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jan 05, 2012 4:48 am

Re: Multi-Contact Selection

Postby Phyll » Thu Jan 05, 2012 3:55 pm

Hi Skullmonkey,

Yes, the listview which can be made to do about anything needs an adapter to fill each slot in the list. You would need an array of names and an array of booleans (one for each name).

There are some standardized adapters used by the spinner that just need an array. But they won't allow you to do multiple selection without extending them and adding the functionality as shown in the second link above.

I would think you could use the listview example pretty much as it is. Of course if you intend to keep a list of names and their status you will need some other parts to read in the list and save it after it is altered. I think the list with the checkboxes is the best, easiest, fastest way to go about it. You don't need to use the database, you could always just keep a text file. Store it anywhere you like. Locally with the program is best for small lists. On the sdcard for really big stuff. Is security very important?

Let me know specifically what you need help with and maybe I could be more helpful.

If you want a way to get projects started faster and study code constructs for Android, helpers and examples and you are working on Windows, download this code writing program: http://betterpaving.com/stuff/t2j_proj.zip
It writes code from a pcode outline. I use it all the time and keep adding to it. Its sort of my tutorial effort.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Multi-Contact Selection

Postby Skullmonkey » Thu Jan 05, 2012 8:08 pm

What you are suggesting is what I am looking for. Except I would like to have the selection saved so when I bring up that view, it will automatically have the people checked that are already on the list. From there, I want to be able to add (check) or remove (uncheck) people to send the message to.

This is basically what I am looking for:
Image

I can upload my source that I have so far but it doesn't have anything on contact selection.

I'm not sure exactly what that program is but from the examples it looks like it just starts the project for you. Eclipse does this automatically for me. Is there any other use for that program?
Skullmonkey
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jan 05, 2012 4:48 am

Re: Multi-Contact Selection

Postby Phyll » Fri Jan 06, 2012 12:39 am

Hi Skullmonkey,

Well I suppose you would store the state of the checkboxes while they are using the list and the activity is displayed but when it is paused you would save the list and the checkboxes. You would restore them when the app is resumed. Or something along those lines. Does that example show you how to retrieve the state of the checkboxes? Do you know how to save these things in a file or sqlite? And I guess you already have the listview looking like the one above?

As for T2J. Eclipse dosen't do what it does and it needs Eclipse to start the project anyway. But it can set up multiple activities with multiple view elements in them and write all the stubs at once. Besides showing how to do a lot of helper functions and classes to send and receive on the internet, read and write files, get sms messages, it has a couple of pretty much complete examples of apps and other stuff and adding them to the project too. But maybe you're too advanced for it. I made if for myself so I wouldn't have to remember and look up so much and it was good practice. It is what it is. I've seen some pretty fast typers but it can write several hundred lines in a couple of seconds.

Let me know what you want to do next.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Re: Multi-Contact Selection

Postby Skullmonkey » Fri Jan 06, 2012 5:34 am

It does not. Its actually not an example but an app on the market called multi-texter. The developer is a member of XDA and I sent him a PM a few days ago but it looks like he has gone inactive.

I really have nothing pertaining to a contact selection at all in my coding. I am basically starting from scratch on this part of the project. Like I said, I can upload the source of what I have so far if you want me to.

I just want to take this one step at a time. I guess the first thing to do is to get a working list view with check boxes to select the contacts and then go from there?
Skullmonkey
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jan 05, 2012 4:48 am

Re: Multi-Contact Selection

Postby Phyll » Fri Jan 06, 2012 4:11 pm

Hi Skullmonkey,

Well then I guess you need an activity with a listview and adapter. I was just helping somebody else with a similar project (button instead of checkbox). I guess I've usually set things like that up differently. My contacts list which is primarily a phone list has a listview. Once selected, if you longpress the list item it brings up a menu and you can act on the item, call, edit, delete etc. I think you just need a view adapter that has the name and number and your checkbox. I guess you are going to supply the data in the resources?

What would you like some help with. Making a UI that looks like that?

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Multi-Contact Selection

Postby Skullmonkey » Fri Jan 06, 2012 4:51 pm

Phyll wrote:What would you like some help with. Making a UI that looks like that?

Correct. I would like to get the list set up with a name (doesn't have to include numbers and would like only mobile numbers to show up so I don't accidentally send texts to a landline) and a checkbox for now. I can add a save button or whatever.
Again, I am fairly new to java so I don't understand too much of the coding yet.
Skullmonkey
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jan 05, 2012 4:48 am

Re: Multi-Contact Selection

Postby Phyll » Fri Jan 06, 2012 8:46 pm

Hi Skullmonkey,

I don't have a lot of time right now but I wanted to send this screenshot to you. I have been experimenting with the dividers to see how they might have done that.

Image

Might be a good start on this if you want it. Has buttons instead of checkboxes but they could work too. Needs some better art.

Let me know what you think.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Multi-Contact Selection

Postby Skullmonkey » Fri Jan 06, 2012 11:43 pm

Yeah, I can try to convert it over to a check box. I wouldn't know how to populate the list with contacts though.
Skullmonkey
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jan 05, 2012 4:48 am

Re: Multi-Contact Selection

Postby Phyll » Sat Jan 07, 2012 1:12 am

Hi Skullmonkey,

Were you thinking about getting the names from the contact list always or just be able to fill it from there and then pare it down to what the user wants? Always is easy. Once requires the easy part and then storing separately. My personal choice I think because the other way does get numbers you don't want and more of them than you want to go thru all the time. I guess the one I have here is headed towards a form to enter and edit a name and number to the list. But I did convert it over to a checkbox already. Problem with that is the text part of the checkbox. I didn't want it but it seems to take up some room (even when its empty) on the line. Didn't quite get that one put to bed.

I'll attach what I've got so you will have something to study.

EDIT
Just happened to think, if you try to run this, import it it won't work directly in your installation probably.

EDITEDIT
I found a couple of problems with the first one so I replaced it with this newer one. Sorry for any inconvenience.

Phyll
Attachments
Texter.zip
Texting Activity
(58.04 KiB) Downloaded 45 times
Last edited by Phyll on Sat Jan 07, 2012 6:43 am, edited 1 time in total.
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Multi-Contact Selection

Postby Skullmonkey » Sat Jan 07, 2012 2:06 am

All contacts always. I'm not really sure what you meant by the 2nd part. You mean like a search bar?

Thanks for the upload, I'll take a look at it a little later tonight.

EDIT:
Ok, these are my notes after spending a little time on the code:
1: The numbers are still hard coded in. I need it to pull contacts from the list in the phone (I am assuming that ContactContract will need to be used.)
2: I'm guessing I should clear up what this program actually does:
Image
The program was made to send out a text message to a group of people at literally a push of a button. Since the fire department I work at ran out of pagers, I use this program to send out a text to the people that don't have one. So I just hit a button depending on the call type and put my phone down.

I have (or will have) 3 screens: the main one you see now for my department, a mutual aid screen, and (don't have this one yet) a contact selection screen.

Right now, I have an array of numbers stored in an XML file. When I hit one of those buttons, it will set a pre-defined (I don't have to enter in the text to send) text to everybody on the list.
Skullmonkey
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jan 05, 2012 4:48 am

Re: Multi-Contact Selection

Postby Phyll » Sat Jan 07, 2012 6:55 am

Hi Skullmonkey,

Looks like a nice project. I think I see how it could be done.

I found a couple of things wrong with what I sent you today. I replaced it in the previous post. Please take a look at this revised one and throw the other one away. It doesn't do everything you had in mind but it will text to a list.

You know if you replaced that list of buttons with a programmable array of buttons (like a custom menu from T2J) or just a listview or grid, you could make it so it could select a list for calling or editing or deleting and you would have a pretty complete system.

All you have to do is give the sending part of that example up above a string array to do all the sending. So your list of menu or list items or buttons would just load the array and call the routine.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Multi-Contact Selection

Postby Skullmonkey » Sun Jan 08, 2012 1:27 am

Phyll wrote:You know if you replaced that list of buttons with a programmable array of buttons (like a custom menu from T2J) or just a listview or grid, you could make it so it could select a list for calling or editing or deleting and you would have a pretty complete system.

Ultimately, I plan on making a version that will allow you to make a custom list and all that, but that is down the road. I am taking this one step at a time.

I downloaded your updated file and I am still confused on how to pull up the contacts list from the phone. I have uploaded my source and will PM it to you.

I tried to work with a contact selector but I cant figure out how to add a check box in it by looking at your code.
Skullmonkey
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Jan 05, 2012 4:48 am

Top
Next

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Feedfetcher and 15 guests