-3

Here's what I need to do: Depending on what category is chosen in my app, anywhere from 0-5 Layouts that have a heading with a button, text and image on the button. All the text will be different for each Layout. I'd like this first half to use templates that I could duplicate as needed and give unique IDs.

The buttons will then show another layout that could be duplicated the same number of times, but each new layout, with individual elements, has to be unique. For this second half, I'd also like to use some templates that I could duplicate as needed and give unique IDs.

Is there a way to use strings to give a unique id?

This all needs to be with min api level 8. And if that doesn't work, what is the minimum api level that will work?

Update: My question is being downvoted with no explanation so maybe I should give some background.

First, I thought I could produce a template and just give it a unique id each time it's duplicated, but it requires an int rather than a string. I could create int constants, but that might require me to create variables that might never, or rarely, get used.

I tried creating a layout from scratch, but I don't know why it wasn't working; the code just quit, and Gradle wasn't giving me any errors. Yes, I could put that code here, but I don't really want to do it that way anyway.

I don't know what else to try so I wanted a push in the right direction from one of the largest collections of Android developers, something this question is currently debating, as @GEMISIS gave, which hopefully will help.

Thanks for your input!

Community
  • 1
  • 1
craned
  • 2,991
  • 2
  • 34
  • 38
  • Why in the world is my question being downvoted with no explanation as to why? I haven't found another post anywhere that explains what I'm wanting to do. – craned May 20 '14 at 21:36
  • The problem is that most of what you are asking can be found in a Google search. Both of my solutions below were found with a quick Google search. The direction you should go is reading those posts, figuring out how to implement them for what you need, and go from there. If you end up with specific questions, Google them first, and then post on here if you really cannot find a solution. – GEMISIS May 21 '14 at 04:02
  • 1)You're right; my 2nd question could have been found in a Google search. I was in a meeting when I responded and chose to go off memory. 2) Anything on SO can be found in a Google search. I don't see that as a legitimate reason to downvote. 3) I spent at least a full day on Google search and haven't found a great solution yet. That's when I posted my question. I'm glad there are people like you on these forums with better search capabilities that me so I can find the answers I'm looking for. Today was my day to start looking into your answer. – craned May 21 '14 at 15:24

1 Answers1

0

It sounds like you could just use a fragment for your "templates". See here for a quick tutorial on fragments. As for unique ids with strings, I would look at this post about how to create unique string IDs: How to generate a unique hash code for string input in android...?

Community
  • 1
  • 1
GEMISIS
  • 434
  • 3
  • 11
  • I don't believe fragments work with min apk 8. Is there another way this can be done without fragments or does the min apk need to be bumped up? – craned May 19 '14 at 19:52
  • They do. You'll need to use the support library for them (again, read that link on fragments above, it specifically says they work with API 7 and above when using the support library). – GEMISIS May 19 '14 at 21:18