So, what I have currently is basically
displayText.setText();
scroll.fullScroll(View.FOCUS_DOWN);
This goes over and over with user input, and eventually displayText gets big enough that it moves on to another line, which is why I want it to scroll down. I'm pretty new to this and so I'm not too sure what I'm doing wrong.
I'm not completely sure about what you want to do, but if I understood well, look at this, it might help you : How to get the Android TextView to scroll down to the end automatically?
Related
TL;DR available at bottom.
I'm working on a Monopoly game, and during each player's turn, there are quite a few times when they need to make a decision. Usually, the decision is just "yes" or "no". So far, I've been doing this:
public static boolean userChoosesYes(String question)
{
String [] choiceStringsArray = {"yes","no"};
List <String> choiceStrings = Arrays.asList(choiceStringsArray);
ChoiceDialog <String> dialog = new ChoiceDialog<String>(choiceStrings[0],choiceStrings);
dilog.initModality(Modality.NONE);
dialog.setContentText(question);
Optional <String> result = dialog.showAndWait();
if (result.isPresent()){return result.get();}
return null;
}
First, I'm aware that there's no easy way to do it. I know that buttons are supposed to activate methods, not return values, and if I want a button to return a value I should use Dialog. However, Dialog opens a new window, which I've been told gets in the way of the game. So far, I've thought of a few ways I could do this, none of which seem very helpful.
The first idea is that I could create fifty or so yes/no buttons, one for each of the times I need to ask yes or no, and try to set those buttons to managed each time I need them. However, not only would that be a LOT of buttons to work with, I'd need to end a method every time I want to ask yes/no and continue the method in two different new methods, one for yes and one for no. My second idea was to have two windows always showing, one next to the main window, and do something similar to showAndWait but without making the window close when a button is pressed. However, I have no idea how to do this, and the two windows still might distract the user. My third idea is to make a boolean of "userHasEnteredAResponse", and pause the method while that is false, but I have no idea how to do that. My friends have suggested doing:
while (!userHasEnteredAResponse){}
or
thread.sleep();if(userHasEnteredAResponse){thread.continue();}
But neither of these work (I've tried), and I'm not very familiar with thread.sleep() and thread.continue(). Any ideas?
TL;DR: I want to be able to use something like javafx Dialog without opening a new window.
First of all, I want to tell you that I'm new here and I'm from Spain and my english level isn't so good, so please... try to understand me haha. Also, you must know that I'm a telematic engineering student and programming is just my favourite hobby. With this info, I just want you to be comprehensive with my question: I know that it's a rookie question and it's worse when I'm pretending to create an Android game... But I'm learning bit by bit.
PROBLEM
The problem that I have is the next one. I want to set a .PNG image in my principal activity called "*activity_principal*". This image has lot of empty space and the background is initially black (due to the theme selected at the beginning I guess). Well, this image has some details in black and them merges with the background colour.
My first solution was trying to set the two backgrounds from the XML corresponding code, but rapidly I realized it was impossible to use it twice in a same layout. So I thought that it would be fixed by the next way: I set the "android:background="#android:color/white"" in the XML file and in the .java file I set the other resource to the background:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
RelativeLayout fondo = (RelativeLayout) findViewById(R.layout.activity_principal);
fondo.setBackgroundResource(R.drawable.prototipoestructurapantalla);
}
I used to use this structure and never had problems but today, trying to do this, I noticed something strange. Due not to find the error, I put two breakpoints at the lines under "setContentView(..." and debugging, when the cursor reached the last code line "fondo.setBack..." the variable "fondo" was "null" and I think that there is the problem, so when I resume the debugging the app crashes...
I hope you can help me. Thank you!
The problem is that findViewById(R.layout.activity_principal); is going to return null.
You are passing a layout ID (R.layout.activity_principal) instead of a View ID.
It should look something like findViewById(R.id.fondo);.
so I have been working on developing a GUI for an upcoming project,
and I have to admit that even after about 2 years of Java, I'm still not good at GUI design and programming.
First of all, here's a screenshot of the current version of the JFrame:
I made a little custom JPanel that is going to display a graph later on,
for now it's just random. It's the thing in the lower right. Now if I just repainted that and did all my stuff, nothing would be wrong, but I have to update the JTextArea (which is included in a JScrollPane by the way), I every time set the caret to the very last position, so that it automatically scrolls down. And this causes, in my own custom JPanel, small dots and lines to appear and flicker, which I believe is caused by the JTextArea.
When the window has certain proportions, or if I don't update the caret position, this doesn't occur.
I have already tried a few things: Synchronizing everything related with the EDT, scheduling my repaints, etc. but nothings seems to help.
Has anyone ever come across a similar situation and knows how to fix it?
I could really use some help here.
Thanks in advance,
Tom S.
I think is too hard to say something wise in conections with #camickr's Text Area Scrolling
I have a rather large application written with LWUIT. With only a few screens that have the problem.
The problem:
When the page loads, everything looks fine. but when you scroll you can't scroll to the bottom, and when you click on a list it selects the item below where you clicked and not on where you clicked
However, when you click a select the list for a second time, all is fine. Also when a dialog pops up, after clicking it away, all is fine. And when I forget to call show() or repaint() he does not paint anything but when i try to scroll he shows() everything and he calculates it correctly.
I'm really puzzled about this problem. I'm searching on it for a long time now. And I would love to gain some new insights here.
After 5 days of searching on it, I finally found the solution. You have to call form.show() after you have added everything to your form. and not before, like I was doing.
Most of the time it works fine in both ways. Just not always.
I'm not looking for exact code here, just a direction on what to look for and what I should be reading about so I can figure this out.
I have a layout that I would like to remain static, with only the listview changing depending on what's selected from the list. I've reloaded data in the list, but I would like the fancy transition animations between choices, and would like the app to go to the previous menu when pressing back.
Someone suggested using a viewswitcher, which seems like it'd be great, but I am still unsure about how to fill a listview in a layout with a regular row layout, then on selection do an animated transition to a custom row. Also, it seems the viewswitcher is limited to two views, so it may be a limitation when I want to go a few menus deeper.
Preferably, I'd like to put each menu in it's own class so that I can handle filling it in that class, if possible...
Hope this isn't too vague, but if it is I'll be more than happy to explain myself further.
Don't know if it's what you meant but have you tried showing and hiding the views?
findViewById(R.id.listViewID).setVisibility(LinearLayout.GONE); //hide the one you want
findViewById(R.id.listViewID2).setVisibility(LinearLayout.VISIBLE); //show the one you want
Hope it's what you meant :)