textview or something else - java

I'm trying to find the best approach to handle a user clicking a button, setting the text of that button to (in my attempt) a textview and then automatically move onto the the next textview to update on the next button press.
At the moment I can do this by manually specifying each element by ID to update but there must be a better way, or a different approach.
An example: imagine a table with 2 rows of each 4 columns (each contains a textview) and below that 6 buttons. When any button is pressed the first time the textview of the first column is set to the button text, the next press of any button sets the the textview of the second column is set to the button text, and so on. When a row is complete it will start back at column one of the next row.
at the moment I'm using a hard coded function triggered by the onclick event, I realized that I could implement some counter and user row[i]_col[j] (or such) but is there a better way to approach this (eg. some way similar to changing focus on edittext)?
public void setValue(View view) {
TextView textView = (TextView) findViewById(R.id.textView_row1_col1);
textView.setText(((Button) view).getText());
}

If i understood your problem correctly ,
I would suggest using an array of Textviews instead of using findviewbyid so much (very pricey memory wise )
TextView [][] txtArr = new TextView[XSize][Ysize];
Initial that in the start once and use it in the on click later.

Related

How can I do this without starting any activity or fragment

How can I do this When User Click On the Next Button Activity Should not change only data should change for example if there is TextView then its data should change and so on.
I want output like This Gif
If you have any doubt please feel free to ask in the comments
I think this is able to do with the help of animation.
There are a couple of ways you can do this. You will need to have a list of data which will hold the title and the images. Then you can do one of the following
On your button click, change the text of your TextView and set the image resource of your ImageView by fetching the next item of the list manually each time.
You can use a ViewPager and update the current page when you click on the button
You can use a ViewFlipper and manually add Views based on your data and change views on button click
To achieve this view take on int counter with initial value 0 and use CountDownTimer method.
Create list which contains image and text values in model. on CountDownTimer method every tick you can increase the counter and set image and text again from the list index.

android refresh/restart activity with updated variables

I'm making a quiz app and I'm looking to have my "practice questions" activity refresh itself with new questions with a previous/next button is pressed. The questions are in an array placed inside a singleton "Global" class.
I want to update/refresh the activity so that a new question and set of answers pops up (ie. a counter is incremented/decremented when the previous/next button is pressed), but I don't want to reset the singleton class, which would re-randomize the questions in the array. Intentionally, they're randomized every time the activity is accessed from the main screen. I also have other variables (ie. counters, totals, flags) I would like to update with each passing to a new question.
Can someone point me in the right direction?
If it helps, the buttons are created and ID'd in XML And the Java file fills the buttons/textviews with strings.
If you just need to update the text inside the views, then you don't need to refresh the Activity. Instead, you can write an updateViews() method and call it when the previous/next button is pressed.
For example:
private void updateViews(String question, String answerA, String answerB,
String answerC, String answerD) {
TextView tvQuestion = (TextView) findViewById(R.id.question);
TextView tvAnswerA = (TextView) findViewById(R.id.answer_a);
TextView tvAnswerB = (TextView) findViewById(R.id.answer_b);
TextView tvAnswerC = (TextView) findViewById(R.id.answer_c);
TextView tvAnswerD = (TextView) findViewById(R.id.answer_d);
tvQuestion.setText(question);
tvAnswerA.setText(answerA);
tvAnswerB.setText(answerB);
tvAnswerC.setText(answerC);
tvAnswerD.setText(answerD);
}
Obviously, you would need to tailor this approach to your views and data, as well as keep track of state (current question number, etc.), but this should give you an idea of one way to move ahead.

moving focus over sequential editText controls in android

I have 4 editText
I want the user to set one digit in each of them sequentially.
how would you suggest enumerating the controls?
Is there any attribute I can override which will save the next editText control's id?

Programmatically set TextView with Scrollbar on the top

I have a problem with TextView that has ScrollBar. I know that in order to create scrollbar on the textview, I need to enable this on the xml:
android:scrollbar="vertical"
and in the code.java, I set like this:
tvChapterDesc.setMovementMethod(new ScrollingMovementMethod())
Then, now user could scroll the TextView, if it is more than the defined number of lines. (say maxlines = 5).
However, I have a Button where if it is clicked, it is supposed to scrolled the textview to the top, can I do this? How? For example that the textview has 1000 lines, and there is a button "top". if user click button "top", it will be scrolled to the top immediately, so user can start reading to the beginning of the textview again. How to do that?
You should be able to use the scrollTo function on the textView.

Can I show up the textbox editor on an image icon in Android?

all,
We know on Andorid, for a EditText, by default, whenever the EditText is clicked, the soft keyboard pops up to let you enter text. When you click DONE, it closes out and put the text directly to the EditText.
Now, what I am trying to do is, instead of an EditText, I have an ImageView which is to let user enter some comment.(So the ImageView actually is an comment icon). I wish whenever the icon is clicked, it pops up the text editor with user previous entered text, again once the DONE is hit, it closes out and I can save whatever text there back to a string member of the Activity. Is that possible?
So far, all I've seen about InputMethodManager is on EditText control, If it is too complicated, I probably just put an EditText into a sperate Activity.
Thanks.
There are many solutions:
One is to use custom dialog: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
Second one is to use a transparent activity on top of that one.
Then you could use FrameLayout and insert another view in an exact position...
I think you should try the frist or second one. Every ImageView can be easily converted into a button by adding onClick event to it.

Categories

Resources