Android: How to add TextView Dynamically? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm building a surveying app. On the creation of survey activity, I am having trouble how to implement the number of options to a particular survey?
For example let's say I want to ask:
What is your favourite Programming language?
1. C++
2. Java
3. C#
4. Python
5. I hate programming!!
Then in the next survey, I want to ask a Yes or No question:
Do you like ice cream?
1. Yes
2. No
See, options vary depending on the survey question; therefore, I am thinking of first asking the user how many options they would like to have then show them. However, I am unsure of going about doing so.
Can anyone please help me? I'll greatly appreciate it.

You can add TextView dynamically with this code
TextView textView = new TextView(<context intance here>);
textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setText("Sample Text");
Then add created TextView instance to your view container:
viewContainer.addView(textView);
You can change your view's layouting by its LayoutParams.

if you have radio buttons to chose from your answers you can try to only show as many radio buttons as many answers you have with a if clause

Related

JFrame using one component on two different panels makes it dissapear [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Basically I have two panels and one label. I want this label to show in the exact same position on both panels(I'm using the card layout). But when I use the same component it doesn't show up on either panel, but it does if it's only being used on one panel. Does anyone know why?
Thanks.
No you can't do that. A Swing component can only have 1 parent.
But you might be able to create 2 JLabel objects, and give them the same Model, so they always show/contains the same data.

Android Image Looping [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I wanted to loop three images switching like this.
http://www.transum.org/software/SW/SnailRace/DiceAnimated.gif
int i=1;
while(i<5000){
enemyj.setImageResource(R.drawable.paper);
i++;
enemyj.setImageResource(R.drawable.rock);
i++;
enemyj.setImageResource(R.drawable.sciss);
i++;
}
the duration is there but there is no image showing. the image afterwards is showing fine
What you need is AnimationDrawable take a look at official page, or check it on google
You just need to use AnimationDrawable.
This is a blocking while loop - only the last setImageResource will be visible to the user.
I suggest you check out Frame Animations: http://developer.android.com/guide/topics/resources/animation-resource.html#Frame

Android Multiple radiobuttons get selected after scrolling list. Changes its state [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
have listview with each item contains one textview & one radiogroup. Radiogroup contain two radio buttons. My question is when i scroll the listview multiple contact get selected(i.e. as I scroll after selecting some radio buttons, state of radio button changes means checked becomes unchecked) so how should i overcome this. Please do help. I need it.
Try this link.
It has very nicely explained about this issue.
Hope this may helps you... :)

Highlight items in ListView [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my App I have a ListView, which is fed by a LinkedList.
Some of the Elements in the List are "kind of special". which is why I want to highlight them in some kind.
E.g. underline their names or have them differently colored.
Does anyone know how i can achieve somthing like that?
One thing that you could do is to make your own adapter by extending BaseAdapter.
Then, in getView(), you can check the contents of your LinkedList and based on that you can return an appropriate view with underlined text, different colors and so on.
here is a tutorial: http://www.javacodegeeks.com/2012/10/android-listview-example-with-image-and.html

Creating such an Android UI [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am attempting to create an Android UI similar to the one shown above.
This type of layout is fairly common in websites and I want to recreate this for my Android app.
It is a list of names and when you click on a name it expands and displays some customized UI.
Can someone please guide me on how this can be achieved ?
To be specific, the expansion when clicking a name so that a new View is displayed.
Have a look at the ExpandableListItemAdapter class in the ListViewAnimations library.
You can seperately specify a header View and a content View. The content view smoothly animates in to sight when clicked.
I have done something very similar, you can use the code provided here (check src/com/udinic/expand_animation_example/ExpandAnimation.java) to achieve exactly what you are looking for.
Sample code:
final int animationTime=250;
ExpandAnimation expandAni = new ExpandAnimation(expandingView, animationTime);
expandingView.startAnimation(expandAni);
Note that the code would call requestLayout() to perform the animation which is computationally expensive. So if you are trying to apply this animation to a complex LinearLayout encapsulated in a ScrollView, the result would be choppy. In this case try to use ListView to populate the screen instead.

Categories