Getting ImageButton Name - android

I am having some trouble with my code, and I am trying to figure out where each ImageButton is in my ArrayList to see if the problem is there. How do I retreive the name of an ImageButton from an ArrayList?
List<ImageButton> images = new ArrayList<ImageButton>();
images.add(imgbut1);
images.add(imgbut2);
images.add(imgbut3);
images.add(imgbut4);
images.add(imgbut5);
Here, I want to get imgbut1 for images.get(0), imgbut2 for images.get(1), etc. Something like images.get(0).getName(), images.get(1).getName(), etc
Thanks!

imgbut1, imgbut2 are names you gave to your instances. You cannot get the name.
Here are some good examples
Get name java instances

Related

how to pass arraylist of objects to populate each section heading text and its content?

I'am using StickyGridHeaders for GridView with sections.
this library is using R.array.countries to populate GridView with provided data and extracting first letter from passed string array to create section heading.
I m trying to pass an ArrayList of objects that will contain ArrayList for sections text named as "sectionArrayList" and "contentArrayListPrivate" and "contentArrayListPublic".
Now i want to play a for loop that will play till < sectionArrayList.size and will check is there any sections then show section text and then show all contents associated with this section by contentArrayListPrivate.size and similar for others but unable to achieve my target.
Can someone please point me towards right direction how to achieve this task ?
want to achive something like:
I downloaded it and checked to solve your problem. so here is solution.
First of all that project is replaced to SuperSlim it is showing on your given link itself, so get superslim.
Then follow the example in that project to achieve it. In that example there is a file named CountryNamesAdapter.java open it, in the 37th line there i found this
final String[] countryNames = context.getResources().getStringArray(R.array.country_names);
which means the data is loaded from Array resource
replace it with
your data - convert your arraylist to string array and assign it like this
final String[] countryNames = myData.

Implementing OR Condition using Parse Android SDK?

I am new to Parse and i am working on a Project that uses Android PARSE Sdk so i was wondering on how can i make a where query with or condition using the android sdk.
I want to make a query like this [Psuedo code]
Select * from employ where employId is ("1","2","3")
I found this on parse documentation, i don't know if it helps or not.
Edit:
This is what i found on PARSE but its not working
String[] id= {"1","2","3"};
query.whereContainedIn("employId ", Arrays.asList(id));
It returns me an empty list but if i query them one by one i get result... Can anyone tell me whats wrong ?
You can use whereContainedIn to select specific rows. See this post you can get more ideas. https://www.parse.com/questions/different-arrays-and-wherecontainedin-for-android.
List<String> employId = new ArrayList<String>();
employId.add("1"); employId.add("2"); employId.add("2");
query.whereContainedIn("employId", employId);
If you are still not clear. check this https://www.parse.com/docs/android_guide#queries
I have found the solution and i must say its pretty lame of PARSE to not mention this anywhere in there documentation.
The problem was that the values that i was using inwhereContainedIn method were of type String but in reality they were pointers to another table's row.
I was trying to get the values using only there ids[as it is displayed on parse] but instead i had to pass the whole object in order to retrieve them. That was the reason on why it was returning empty list.
The thing is Even though it displays IDs [pointer to object in a table] we cant search using only ID's instead we have to use complete Parse objects if we want to search a table based on Specific Object.

Resource issue, (R.drawable.*VARIABLE HERE*); possible?! ANDROID

I'm having an arrayList with loads of numbers, I want
to have a different image on every number in the array represented by each number... but I dont know how to put a Variable in (R.drawable."HERE"), if its even possible?!
This is what i've tried to do, Im pretty new to android and Java,
so this may seem pretty funny to you haha... (the array is not shown)
String s = names[position];
String img = s.toString();
holder.imageView.setImageResource(R.drawable.img);
Hope you understand my question.
Thanks in advance
//Halle
You can use reflection do do that. See here for an example.

compiling text for textview, including data from SQLite table

A stupid question that Im sure is really really simple - ive been trying to fiddle to solve it myself, but its all very new to me so any wisdom would be REALLY appreciated!
With an android application (using eclipse) if I want to compile text for a text view using some data that is stored in a sqlite database (I have a working dbhelper and table I want to use), what do I do?
For example, I want a text box to say something like:
"hello"+#user_name+"its been"+#days+"since your last visit!"
where #user_name and #days are data in a table which I can currently retreive in a list (only 1 value in the list though).
How do i compile a string to be shown in the text view (and assign this string to the view)?
Help!
String textViewValue="hello "+nameList.get(0)+" its been "+daysList.get(0)+" since youy last visit";
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(textViewValue);
You said you have stored it in arryalist right?
I am not sure if you have one ArrayList or two for Name and Days. (it would be good if you paste some of your code).
If your ArrayList is arrayList then you can get the name atleast like
"hello"+arrayList.get(0); // will retrive first element
Or best way use cursor and fire a query which will store output of following in curser
select Name,Days from your_table where Name='xyz';
then you can use folloing code to retrive data form curser (I am assuming there is only one row in cursor here)
if(cursor.moveToFirst()){
String s = "hello"+cursor.getString(0)+"Its been"+cursor.getString(1)+"days since your last visit!!";
}
now set this s in your textbox.

Conceptual help with Android ListView

I have a working android app using TextView, some formatting (line breaks, rows of dashes) and Linkify to generate a primitive "ListView-like" display with clickable URLs in each "row". I'd like to move up to a real ListView, but I'm just not finding the sample/explanation that I need to take that next step.
I have successfully reproduced the HelloListView sample, starting with the hardcoded string array, and moving to a string array defined in my res/values/strings.xml. I've taken one small step toward my goal by adding my HttpClient code to retrieve a set of data from a service, parse the results into a String Array and feed that into setListAdapter() such that my text and links show up as text-only in ListView items.
I want to move to the next step which is to make each "row" in my ListView launch the browser to the URL contained in the data, either by
(A) clicking anywhere in the row, or
(B) clicking a hyperlink displayed within the row data
For option (A), it appears that I need to have my onItemClick() method issue an intent that launches the browser. That's straightforward, but I don't get how to associate the URL with the item (currently its just one part of the string content for each "row" of text). How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL? Do I need to replace my String Array with an array of custom objects?
For option (B), can I use Linkify? It seems that my string array elements get converted to individual TextViews (inferring from the way the Toast text is generated in the HelloListView sample). Do I have access to that TextView to run Linkify against? Do I need to replace my String Array with a TextView Array and run Linkify myself? Am I completely off base?
Thanks to anyone who can help explain back to me what I'm trying to do, in a way that helps to find my way around the SDK, samples and other helps!
How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL?
Use a regular expression (java.util.regex) to find the URL.
For option (B), can I use Linkify?
Yes.
Do I have access to that TextView to run Linkify against?
Yes. Override getView() in your ArrayAdapter. Chain to the superclass and get your TextView from the result of super.getView().
Even better would be to use Linkify on your strings before putting them in the array in the first place.
Do I need to replace my String Array with a TextView Array and run Linkify myself?
No, and that is really not a good idea. Here is a free excerpt from one of my books that goes into more detail on tailoring the individual rows of a ListView, in case this helps.

Categories

Resources