I've been trying to create a timetable and I have tried different layouts, the best i could get is to use a grid layout.
a preview of how it looks:
The header is a fixed view, I added that manually in the xml file.
but each of the "Off white" cells and cells that contains time are textviews added dynamically using a loop.
However I think it's not the most efficient way of creating this, also I wouldn't be able to locate those cells unless I add an id to each of them dynamically and store those Ids.
This example shows an empty time table. but those cells should be able to expand and merge with others when an event is added.
Is Grid Layout the only way to build this and is there more a more efficient way to locate each cell position?
this is similar to what I'm trying to achieve
I am fairly new to android studio and I am trying to make a car rental app for a university project.
I designed an app which has a horizontal slider containing blocks of different cars however I am unsure on how I would do this, I understand how the slider works and how to add elements to it.
I have a linear layout within the horizontal slider which will contain all of the blocks but I am unsure how to make a block of elements. Within the block it should have two buttons, an image and some text. Here is a picture of the design.
As you can see the available blocks are surrounded by a square. this is what I want, a small container which surrounds my data. Sort of like a div box in html.
Is there a way to do this?
Please just point me in the correct direction!
Many thanks!
It seems like cardviews can handle most of the grouping you want to do. I would reccomend looking into them because they incorporate a lot of material design components right out of the box.
https://developer.android.com/guide/topics/ui/layout/cardview
I have been working on an app that adds views programmatically to a linear layout.
The problem is if I add too many views it will go off the screen.
I would like to know how to check if a certain child has hit the end of the same view group so I could add it into another layout (a linear layout below the first one) before it "flows" and go off the screen. How might I accomplish this?
Rather than reinvent the wheel yourself, I suggest that you check out the FlexboxLayout project by Google: https://github.com/google/flexbox-layout
A FlexboxLayout will automatically give you the behavior you're describing, plus the potential for much more.
Well, there are a good number of ways you could implement this in android other than going through this hustle. What ever you are trying to do at the moment may fall under one of the following cases.
Creating views programmatically most likely means you have a dynamic data set probably from an external source.
Your dataset is limited or static but just more than the average screen can display.
if any of the above apple then you are better off using a ListView or RecyclerView (Recommended). That way your data is full displayed as a scroll-able list and you don't have to worry about some items or views not showing or going of the screen. This can range from simple string list to complex nested views.
This will be very efficient as it will automatically handle optimization and usage of memory as well as performance.
Im currently building an application that implements a GridView. However, i need to split the GridView up. For example, at position zeta the number of columns is 3 then at position 2 3 4 the number of columns change to 1.
I have had a look around but it doesn't look like its possible. Coming from an iOS Background ive done it before in some previous iOS projects so i thought i may be able to replicate it in android.
Any suggestions would be great.
Just a idea not sure if it would work. Making the gridView an auto_fit column,
then based on position make the item cell view width properly so the gridView could either put in multiple cells or just one cell in the row.
I'm writing an Android app that reads a single text file and display it on a TextView.
What I'm doing right now is read the whole file into a String (using BufferedReader and StringBuilder) and display it on a TextView using setText(string). A 700KB text file can take about 2 to 3 seconds before it is being displayed on the screen.
But I've used some other ebook readers on the market and they can display the same text almost instantly. Anyone know how I can achieve this?
Thanks you.
Edit: Many suggest ListView, but it doesn't work for my particular case. This is from my reply to one of the answer: ...[ListView] doesn't work for me for a few reasons. (1) To make the Listview look like a TextView, we have to break the text up on new line character. If I load a single large paragraph, it's just as slow as a loading a TextView. (2) Since a ListView only measures the item on the screen, I cannot know ahead of time the total 'pages' or 'height' of the entire text.
Essentially, the key is to only load the data that you need, when you need it. One way to do this would be to put every paragraph into it's own TextView, which is put into a ListAdapter, which is included into a ListView. There has to be some kind of an index set in place, such that each paragraph knows where in the data file to find. This interface will allow you to load only what you need, when you need it. Your list adapter looks something like this (This code isn't complete, but it should give you an idea at least of what you should do):
class ParagraphAdapter extends ListAdapter{
ArrayList<Integer> mLocations; // Somewhere define this to your locations, I'll leave that for you to figure out
protected View getView(int position,View convertView, ViewGroup parent)
{
mLocations.get(position); // Read the file starting at this position, until the next value
String text; // This is the output of the above
TextView tv=new TextView(context);
tv.setText(parent.getContext());
}
}
It can be noted that Amazon uses a system of paging for the Kindle App. If you have the app, you can see at the bottom of each page what section you are on. Each "page" is probably closer to a sentence or so in length. Then it's just a matter of getting the right page, which can fairly quickly be done.
To add on what #PearsonArtPhoto has said -
I suggest you implement some sort of paging mechanism, to divide your text into pages.
What you should do is split your text according to let's say N +M number of characters per pages.
N = fixed number of characters.
M = number of characters from N to nearest end of line character (so you won't see the last
line being "cut").
I would suggest that if your android device allows you to hold this "in memory" - do that,
and don't try to fetch this from the file one page after the other, but rather fetch from the "in memory" structure - this will improve performance.
Once you scroll and realize you need to fetch the next page, fetch it from the "in memory" structure.
You can use Android Paging Library from Jetpack with custom View or RecyclerView
https://developer.android.com/topic/libraries/architecture/paging
Implement DataSource abstraction that provides List of data ranges
Implement Storage abstraction that provides real data (from Database, Network, Files, etc)
Use RecyclerView and Adapter to display data
Sample app to display content of large files can be found here
https://github.com/YablokovDmitry/FileView
Lucas Rocha built a nice library called Smoothie for that purpose.
http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
At the end of those performance tips for Android listview there's a link to an explanation about Smoothie and finally you'll find the library available on github.
Originally described for loading images, the approach applies for loading text as well.
You must to consider if you are using right components.
Maybe it is mutch better to read lines and put them to listview.
try
List<String> lines;
listview.adapter(new ArrayAdapter<String>(...,lines));
And many times that what you see (Look and Feel) is not like you are think.