how to select multiple contacts in autocomplet textview? - android

I am new to android development. Now i am working in a app that is sending sms multiple contacts in my mobile.for that i am using AutoCompleteTextView with reference here.But by using this i am able to select one contact at a time. But i want to select multiple contacts. Can any body suggest me to do that

May This Help you:
Buddy Use MultiAutoCompleteTextView instead of AutoCompleteTextView
For Reference: Click Here

try multiAutoCompleteTextView. I think it will help you.

use check box to select multiple contacts. Store that contacts in array, then on button click use for loop to send sms form first index to last index of the array.
int cntChoice = myList.getCount();
SparseBooleanArray checkedItems = myList.getCheckedItemPositions();
for(int i = 0; i < checkedItemsCount; i++){
int position = checkedItems.keyAt(i);
boolean isChecked = checkedItems.valueAt(i);
if(sparseBooleanArray.get(i) == true){
checked += myList.getItemAtPosition(i).toString() + "\n";
}
selectedNos[i] = checked;
}
use this selectedNos array to send sms.

Related

How to read Text on any view of any application using AccessibilityInfo?

I am trying to read every item inside a ListView of any application by using AccessibilityInfo class. The problem is that i am getting the total number of items inside the ListView by using the following piece of code:
if(event.getClassName().equals("android.widget.ListView")) {
String className= TextView.class.getName();
AccessibilityNodeInfo nodeInfo= event.getSource();
int i= nodeInfo.getChildCount(); }
But i am not getting the names of items inside the ListView , for example let there are 5 textviews inside one ListView then i want to get the text from that TextViews. I tried to further break the nodeInfo object by using:
for(int j=0; j<nodeInfo.getChildCount() ;j++){
AccessibilityNodeInfo subChild = nodeInfo.getChild(j);
CharSequence subText = subChild.getText();
Log.e("MyService: ","ListView child name: "+subText);
}
So what i am doing wrong in getting the values of TextView's inside ListView ,
or
it is not possible to do so?
I have found the solution by myself and the solution is:
event.getSource() method returns instance of AccessibilityNodeInfo and by converting that instance value to String format we can easily get the results. Just we need is to break the string and get the required result out, in my case the way i did is:
String get_cord= String.valueOf(event.getSource());
String[] first_split= get_cord.split("[;]");
for(int i=0; i<first_split.length; i++){
if(first_split[i].contains("text")){
String[] second_split= first_split[i].split(":");
user= second_split[1].trim();
System.out.println(user);
Log.e("MyService: ","username is: "+user);
break;
}
}`

Check box info retrieve

Hey i am adding check boxes through sqlite , i have to get info about perticular checkbox how i get the information or id ?
here is the code its sample
checkboxLayout21 = (LinearLayout) findViewById(R.id.Textview_layout21);
for (int j=0; j < 12; j++ ){
CheckBox cb1 = new CheckBox(getApplicationContext());
cb1.setText(chkstring1[j]);
cb1.setId(j);
cb1.setTextColor(Color.BLACK);
checkboxLayout21.addView(cb1);
Could you describe your problem a bit more specified.
If you want to save ids and info to your checkboxes you can write your own class that extends Checkbox and add that info there.
If you want to be able to get your checkboxes in a later stage you should save them in an array Checkbox[].

ArrayList not deleting properly

I have a screen where the user selects items he/she wants deleted, then I store his/her choices into an integer arrayList (based on which positions they clicked on the listView).
I then pass the items that they want deleted to a function where I actually delete them from my hashtable that holds all the information. For some reason though, it's just NOT deleting from the hashtable. I've tested and looked at all the variables I'm using to access the data and they are correct. I'm not sure why it's not removing what I tell it to..
Here is the function:
for (Entry<Integer, ArrayList<Deck>> i : listOfDecks.entrySet()) {
for (int p = 0; p < i.getValue().size(); p++) {
if (i.getValue().get(p).getTitle().equals(deckTitle)) {
for (int z = 0; z < deletedItems.size(); z++) {
listOfDecks.get(i.getKey()).get(p).getDeck().remove(deletedItems.get(z));
}
}
}
}
deletedItems is the arrayList that holds what the user has selected as their items they want deleted.
What I see is that you are calling Deck.remove(int) so you're not removing from a hashtable, but from a deck.
What does this method remove(int) of the class Deck do?.

For-loop not working the way i want it to

I have a extremely minor issue that I can't seem to figure out. I'm trying to extract data based on a type of value from an ArrayList> and place it into another ArrayList. The issue is that the for-loop only runs once, which in this case i need it to traverse the entire array and then place the data into the unSuppressedData arraylist.
Below is the for-loop:
for (int x = 0; x < suppressedStatus.length; x++) {
for (int i = 0; i < availData.size(); i++) {
Hashtable<String,String> checkAvail = availData.get(i);
String itemStatus = checkAvail.get("loanStatus");
if (unSuppressedData.contains(checkAvail) == false) {
if (!(itemStatus.equals(suppressedStatus[x]))) {
Log.d("Item Status", itemStatus);
Log.d("Suppressed Status", suppressedStatus[x]);
unSuppressedData.add(checkAvail);
//break;
}
}
}
}
suppressedStatus is a String array
availData is the arraylist i want to extract data from
unSuppressedData is the arraylist i want to place the data in
I believe that it only runs once is due to this line of code:
if (unSuppressedData.contains(checkAvail) == false) {
But i need to this line to check whether my unSuppressdData has the data, if no then will add the data from availData arraylist into unSuppressedData arraylist.
Could it be that i'm writing this piece of code wrongly? Appreciate any insights shed on this.
A good collection type for this sort of thing is the LinkedHashSet. Because it's a set, each element can only be added once. Being a hash, the contains test is quick. Being 'linked' the resulting set is iterated in insertion order.

can't get the text from an autocomplete

I have to create an app in android with a database.In that database I have a predefined list of products.
Now,the thing is that my ap has to offer to the user the posibility to introduce in that list some other products which are not in the list.
To this end, I've created an autocomplete text view in which I introduce a new product and I take the text fro autocomplete and I have to write it in the database
Now,my problem is that when I display the products that I've introduced in the database,the toast text that I use to display what I have in the database it shows me nothing next to "product......".
Now,that may be because when I try to get the text from the autocomplete I get nothing in return?
This is how I read from autocomplete:
mItem = (AutoCompleteTextView) findViewById(R.id.todo_edit_item);
String nou=mItem.getText().toString();
And then I compare nou(which is what I wrote in the autocomplete) with what I have predefnied in the list,so if it is a new product(which was not in the list already) the I add it in the database:
for(int i = 0; i < l; i++)
{
if (nou!=fruits[i])
t=true;
else t=false;
}
if (t==true)
{
db.insertTitle(nou);
fruits=db.getAllfromDB("Fruits","fruit");
l=l+1;
}
Anyone any ideas of what I'm doing wrong in here cause I can't figure out.I'lll be here for further details.Thank u in advance:)
You compare strings using != instead of using !nou.equals(fruits[i]). also you compare to all elements in array each time, since you so t is always the value of the comparison to the last element in the array whether a match was found or not.
It should be written like that:
t = true;
for(int i = 0; i < l; i++)
{
if (nou.equals(fruits[i]))
{
t=false;
break;
}
}
if (t==true)
{
db.insertTitle(nou);
fruits=db.getAllfromDB("Fruits","fruit");
l=l+1;
}

Categories

Resources