How can I do this without starting any activity or fragment - java

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.

Related

Android studio: How to dynamically display and refresh a custom list which is horizontally and vertically oriented at the same time?

So I've been developping an app on Android Studio and at some point I need to display couples of values composed of texts and images but I have some issues with the display.
Let's say here that I want a list of fruit names associated with a picture, I'd like to display it that way :
Example
Each image and its related text is in linearlayout, so it's a list of linearlayouts.
The "add fruit" button open an alerdialog where the text and the image can be chosen, by clicking the 'ok' button in the alertdialog the name and the image are saved in a sqlLite database (which I already have programmed), and the linearlayout has to be added in the current list as the dialog is dismissed.
So the issue here is that:
I don't really know how to dynamically display each one of these linearlayouts in this specific order.
I don't know how to make it so that when a new fruit is added and the dialog dismissed, the list in the activity is refreshed directly.
I've been thinking of using a listview but listviews are only horizontal OR vertical but in this case I kind of need a mix of both.
Another idea was to delete the layout containing all the linearlayouts (all the list) when a new fruit was added, and then take my database to create all the linearlayouts again. But dynamically I don't think it will work, the refresh won't be done (?)
My last idea was to create a fragment and use my database in the onCreateView method to display every elements. And to refresh it, I'll just detach and attach again the fragment to the activity each time I add a new element.
I don't think my ideas are the optimal or even a correct way to do it, I've been struggling with it for a while. If you have any suggestions or ideas to help me, it would be great :)

textview or something else

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.

ImageView Onclick Animation

Below is a picture of my app, I am currently using a modified version of this app to show my expandable content. Now my problem is with my ImageView, I currently have 3 layouts, one for the main dialog (with listview), one for the listview title & arrow and one for the item details (item row once expanded). I want to add animation to the ImageView so when you click the image or title textview, the list will expand and animate the change. How can I do this? I cannot get the onClick to work because it doesn't know there are 2 imageviews, it seens only one...
I will assume that your ImageView is this arrow inside your ListView element (because you didn't write it clearly enough).
You probably shouldnt try to attach onClickListener to your ImageView at all (nor to your ListView element title). The good way of implementing what you want you achieve would be to use ListView's onItemClickListener to detect clicks performed on specific items inside your listview, and then expanding appropriate expandable content.

Showing data from Database in Activity in page by page style

I am getting text data from database. I am using Textview to show data
![Textview with scrollView]
I want two button at the bottom of activity (next) & (previous) which show data from database in pages style.
--> user click on next button
it shows scrolls data in that activity like pages
Basically i want to remove Scrolling and add pages turn feature in activity ![buttons used][1]
If i understood your question correctly you are trying to break incomming text into pages so that it fits your screen.
Firstly try to check Breaking large text into pages in android text switcher or view flipper
Instead of the viewflipper try using viewswitcher, which allows you to switch views after calling `getNextView() method. You only need to call this method with the "Next" button.
Hope this helps you ...
You can use ViewPager for this purpose, sample tutorial for ViewPager. First create a list containing you database values and then pass the list as parameter to adapter. You can also add next and previous buttons and use setCurrentItem method to navigate to next and previous accordingly. Hope it helps!!!

How to put a View into Bundle

I'm adding dynamically created EditTexts to a layout (onClick button method). When I rotate the screen the added edittexts disappear. How can I add them to a bundle to put them in the onSavedInstanceState method? Or, is there another way to do this? I know I can save the text, but is there a way to keep the screen layout when I rotate it? If the user presses the button and adds five EditTexts(with or without typing anything) I need to save this layout when the screen is rotated (I basically need to dummy-proof my app :) ).
Thanks in advance!
You cannot add views to a bundle because they are not parcelable / serializable. The only stuff you can and should save into the bundle is the current state of the activity.
You could maintain a list data structure or a counter variable that keeps track of the dynamically created views. Also save the string values of the EditTexts. In onCreate you should interpret that information in order to recreate the views and their states.
you can't save a view. bundle is just a pair name-value. of course you can save the text and then render it again. the way is just you said.
onsaveInsatnceState(bundle save) save the text as save.putString('text1','bla bla') of course you need a loop to save all your edittext.
then in oncreated( bundle save)
you can get what you have added by save.getString('text1')
Views itselfs doesn't represents information that you need to save. Instead you should save their coordinates, width, height, value etc.
Your can save your view data into a class or into a arraylist.
when your fragment activity will restart than you fetch data from saveinstance state in oncreate function.
Use this function setRetainInstance(true). after using thing function your fragment activity will not destroy.

Categories

Resources