Make excel like interface for android app - java

The question is how to make excel like interface for table with possibility of text modification.
Now i have parsed excel file to strings array and passed it to GridView structure.
GridView gvMain;
ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
gvMain = new GridView(this);
gvMain.setAdapter(adapter);
Basically, this construction doesn't allow me to modify text in the cells. What i want to achieve is a EditText like behaviour for each cell (or you can say excel like behaviour when you can click on the cell and type what ever you want). As i understand for achieving this i must somehow override Adapter's getView method (?). Is it possible or i'am using unappropriate API (GridView)? Actually, i have tried with TableView, but i mentioned that for some reason this stuff works very slow (i have big excel file).
Can you help me to choose an appropiate way for solving this task? Thanks!

Related

More detailed list view on android?

I'm trying to design a page for my app that will be a list of places. I need each list entry to have a picture, text below, short description, and some other info, address
The list view fragment examples that I've seen simply have one or two lines which won't really do what I need it to... where do go from here? I'm not sure what to search for, nothing useful has come up so far..
You are going to need to make a custom ArrayAdapter.
Check out some of these examples:
Android Custom Listview with Image and Text using ArrayAdapter
Android Custom ListView with Images and Text – Example
Customizing Android ListView Items with Custom ArrayAdapter

Java & Android: Best way to create a dynamically expandable list of EditTexts in an activity?

as I'm very new to Java and Android programming, I'm slowly getting used to the Android studio and the resource system, xml management and so on..
I'm trying to create an activity with a start count of 10 EditTextes, vertically listed in a LinearLayout.
Till this point, I can manage everything with a XML file & hard-coding the 10 EditTextes.
The problem with it is, that I'd like to provide a button that can be clicked by the user to automatically expand the list, for example add 10 more EditTextes to the list while runtime.
AFAIK, I can't solve this problem with XML only.
I know, I can get the layout (XML layout) to an object in my MainActivity class using LayoutInflater().inflate...
Here's my question:
Is it the right way to define the layout in a XML file and modify it with the method described above or would it be better to create the whole layout with Java in my class:
LinearLayout layout = new LinearLayout(this);
// add EditTexts
// set attributes
//setContentView(layout);
Are there any disadvantages using this way or is it the same as doing it with XML ? I mean, to address the created EditTexts later again, I also do have to pass an ID to them, so I also have to create an ids.xml where all those IDs are listed. That sounds like much work for me..
Am I on the right way or are there better options to create/manipulate layouts?
If you want to fill a listview with multiple views, it'll be best to use an Adapter. An Adapter can be used to fill a list, and add rows to this list.
If you want a tutorial on how to create a list: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
The best part about an Adapter is, that you are able to create a custom layouts for it. So if you want to have an List Item with only EditTexts or ImageViews, it's easy to create.
In the end, you'll only have 1 layout file for the row and 1 layout file which will contain the list.
Inflating a layout is always easier than to create them like " LinearLayout layout = new LinearLayout(this); // add EditTexts // set attributes //setContentView(layout);"
There are a lot of tutorials on how to create an Adapter, you'll get it!

Printing in TwoLineListView in android

I wonder if it is possible to print in TwoLineListView like in TextEdit? For example if I want to print some word in line1 and translation in line2? Is there anything like twolinedtextview.add("word,"translation"); ? I need my text to appear in listview when i press the button.
1. If you are using default ArrayAdapter with the ListView, then you can use ONLY ONE TextView.
2. But you can very well do this with the help of Custom adapter by using BaseAdapter or
ArrayAdapter..
See this link for an easy tutorial:
http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html
you can subclass ArrayAdapter class, override getView(), and construct your rows yourself. The getView() method is responsible for returning a View, representing the row for the supplied position in the adapter data.
If you don't want to extend ArrayAdapter (like the others suggested), you can always use a SimpleAdapter
Here's a short tutorial about using it for 2 line list.

How to create a table dynamically?

I know that it's possible to have an XML file with a TableLayout, and another XML file with a row. And then it's somehow possible to add rows, from the second file, with custom content in the java code to the table in the first file. But I can't find an example that shows how this is done. So, does anyone here know where I can find an example that shows this? I know that I have seen it before.
Dynamically adding rows to TableLayout
Dynamically add rows to TableLayout
First results using Google. Whatever... the idea is really simple:
Get a reference of the TableLayout (either one declared in a XML file, or created by hand using new TableLayou(context))
For each row you want to add, create a new TableRow object. Again, you can do so by using an already defined TableRow in an XML and inflate it; or you can just created by using the new operator.
Add the items you want to put inside each row by using the addView method. Sometimes you will want to specify some TableRow.LayoutParams.
Add the TableRow to the TableLayout.
Once you have your TableLayout, you can inflate and add rows using:
TableRow row = (TableRow) LayoutInflater.from(this).inflate(
R.layout.table_row, tableLayout, false);
tableLayout.addView(row);

Sorting my ArrayAdapter doesn't change my data source

I am having a weird issue. I have an ArrayAdapter which I am sorting. This displays properly on my screen, however when I check the actual data source, the contents have not been sorted. How can I ensure that sorting my ListAdapter will also sort my data source?
Collections.sort(quotes, new PercentChangeComparator()); //sort my data source (this isn't necessary)
quotesAdapter.sort(new PercentChangeComparator()); //sort my ListAdapter
Toast toast = Toast.makeText(getApplicationContext(),quotes.get(0).getSymbol(), Toast.LENGTH_SHORT);
toast.show(); //this shows that my data source hasn't been updated, even though my ListAdapter presents my ListView in the correctly sorted order.
For example:
If my data source is [10,9,1,20]
after sorting my ListView will show [1,9,10,20]
but the data source will still be [10,9,1,20]
How can I resolve this?
It's the other way round: sorting your data source will order the ArrayAdapter.
I assume you've done something like this before.
ArrayList<PercentChangeComparator> quotes = getQuotesFromSomewhere();
QuotesAdapter quotesAdapter = new QuotesAdapter(this, R.layout.xxx, quotes);
Then, if you sorted quotes, notifying the adapter that the dataSet has changed should sort the list
Collections.sort(quotes, new PercentChangeComparator());
quotesAdapter.notifyDataSetChanged();
This is working for me, I hope it helps.
One important thing: if you recreate the source array (quotes in this specific example), the Adapter won't read further changes. Thus, if you need to modify the content of your ListView, do:
quotes.clear();
quotes.add(...);
quotes.add(...);
Also, make sure you implemented correctly the Comparator. If you execute this
Collections.sort(quotes, new PercentChangeComparator());
and quotes isn't sorted, then the problem isn't related to the Adapter but to the comparation.

Categories

Resources