Check box info retrieve - android

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[].

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

Get the ID of dynamic Views in android

I retrieve data from the internet. I add the views dynamically to a layout. I get the ID and the name :
for (int i = 0; i < productsList.size(); i++) {
TextView tv[] = new TextView[productsList.size()];
tv[i] = new TextView(LoveActivity.this);
tv[i].setText(String.valueOf(productsList.get(i).get("name")));
tv[i].setTextColor(R.color.black);
tv[i].setId(Integer.parseInt(productsList.get(i).get("id")));
ID = tv[i].getId();
tv[i].setOnClickListener(LoveActivity.this);
linearLayoutWithData.addView(tv[i]);
}
Now I want to set the ID of an added view to the ID which I get from the internet. To check this I use:
ID = tv[i].getId();
But ID become always the size of the Array..
Thanks for replying :-)
In every Iteration of your loop the variable ID gets overwritten. So the ID you receive after the loop is finished is the ID of the last view you added.

how to select multiple contacts in autocomplet textview?

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.

Store multiple dynamic EditText value

I have a code adding multiple EditText. How can i store them into a array. This number 10 is just example, the number may bigger than that. How can i store it after click a button
for(int i=0; i<10; i++) {
String store[] = new String[10];
EditText addAnsMCQ = new EditText(this);
AnswerRG.addView(addAnsMCQ, 1);
addAnsMCQ.setWidth(200);
addAnsMCQ.setId(1000);
}
In your example the store variable isn't actually being used, did you intend do use it for storing the EditTexts?
Instead of using an array of String, just use an array of EditText and store a reference to them:
EditText store[] = new EditText[10];
for(int i=0; i<10; i++) {
EditText addAnsMCQ = new EditText(this);
AnswerRG.addView(addAnsMCQ, 1);
addAnsMCQ.setWidth(200);
addAnsMCQ.setId(1000);
store[i] = addAnsMCQ; //store a reference in the array to the EditText created
}
Then outside of the for loop, you can access the reference to each EditText, e.g.
store[0].setWidth(300);
You need to keep/get a reference to each of your EditText's then you can look up its value with .getText().toString() which you can store in whatever manner you like.
However if as you say
This number 10 is just example, the number may bigger than that.
If the number is going to be larger you should be using an Adapter and a ListView or something to hold your View objects. That will make it easier to get everything on to the screen. And will give you the benefit of view recycling.

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