Using text field with AdapterView - android

Is it possible to use AdapterView with text fields in android?
My query returns a set of values and for each I want to place that within a textfield, so that the user may edit the value.
Also, I want to click a button to create a new empty field, so that I may insert a new entry.
If you know of good example, then please let me know!
EDIT 1
I would prefer to use XML to define ui and I found this informations:
"In this case we create a new id called text1. The + after the # in the id string indicates that the id should be automatically created as a resource if it does not already exist, so we are defining text1 on the fly and then using it." Source http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html
Will this + allow me to autocreate as many fields as needed? Is there a way I can generically specify the layout in XML and then create fields adhoc based on db response?
Many thanks,
Mith

Is it possible to use AdapterView with
text fields in android?
Yes. It will be complex for you (and possibly also for the user), so I would not recommend it unless you have a few months' Android programming experience, but it should work.
Also, I want to click a button to
create a new empty field, so that I
may insert a new entry.
That will get a little complicated.
Will this + allow me to autocreate as
many fields as needed?
No, that is not how you use ListAdapters for ListView rows.
Is there a way I can generically
specify the layout in XML and then
create fields adhoc based on db
response?
Use a CursorAdapter.
Here is a free excerpt from one of my books that describes creating custom adapter classes. Here is a sample project that shows creating a custom CursorAdapter to display the results of a database query.

Related

How to pre-populate Form fields with initial values in Kinetise?

In Kinetise mobile app generator I want to init form fields (like Text Input) with some dynamic (from web service) values. How can I achieve this?
I found the answer myself so I share it if someone have similar problem:
You need to put Form widget into List widget.
Add List widget and connect it to your API exposing those initial values
Reduce items count to 1, disable SHOW MORE
Add Form widget inside that single-item List widget.
edit TextInput of that Form widget and set its initial value being read from proper node of API you pointed to in step 1.
Initial values of other Form fields should be handled accordingly.

Search dialog search suggestion

I have implemented search dialog and online search suggestion. But I want when user click on suggestion to copy string from suggestion list to search dialog and when user click on search button to start searching. Now when user click on suggestion searching is automatic start.
Take a look at http://developer.android.com/guide/topics/search/adding-custom-suggestions.html#RewritingQueryText which lists 3 different approaches to do this as per below:
1) Add the android:searchMode attribute to your searchable configuration with the "queryRewriteFromText" value. In this case, the content from the suggestion's SUGGEST_COLUMN_TEXT_1 column is used to rewrite the query text.
2) Add the android:searchMode attribute to your searchable configuration with the "queryRewriteFromData" value. In this case, the content from the suggestion's SUGGEST_COLUMN_INTENT_DATA column is used to rewrite the query text. This should only be used with URI's or other data formats that are intended to be user-visible, such as HTTP URLs. Internal URI schemes should not be used to rewrite the query in this way.
3) Provide a unique query text string in the SUGGEST_COLUMN_QUERY column of your suggestions table. If this column is present and contains a value for the current suggestion, it is used to rewrite the query text (and override either of the previous implementations).

How to make number picker with only available numbers?

My app is using api 7. I don't know where to start with this challenge.
I have SQLite DB with some numbers stored between 1-99. Now I would like to make number picker for this range which would also remove numbers that are already in DB.
Create a list off the numbers 0-99, then do a query on your database. For every row in the results from the database, check if the list contains is (something like list.contains(number). If it is there, remove it (list.remove(item)) then proceed to the next row
You'll probably have to make your own widget. This will be somewhat involved, and since you are an Android beginner you might better spend your time coming up with a different input method.
In case you do decide to write your own widget, I would recommend extending LinearLayout, then inside of the constructor, doing something like this psuedocode:
setOrientation(VERTICAL);
addView ImageButton arrowUpButton;
addView EditText numberEditText;
addView ImageButton arrowDownButton;
arrowUpButton.setOnClickListener {
int num = myListOfInts.get(currentIndex++);
numberEditText.setText(num);
}
//vice versa for arrowDownButton
you'd also have to create a setter for the myListOfInts.
Good luck!

Conceptual help with Android ListView

I have a working android app using TextView, some formatting (line breaks, rows of dashes) and Linkify to generate a primitive "ListView-like" display with clickable URLs in each "row". I'd like to move up to a real ListView, but I'm just not finding the sample/explanation that I need to take that next step.
I have successfully reproduced the HelloListView sample, starting with the hardcoded string array, and moving to a string array defined in my res/values/strings.xml. I've taken one small step toward my goal by adding my HttpClient code to retrieve a set of data from a service, parse the results into a String Array and feed that into setListAdapter() such that my text and links show up as text-only in ListView items.
I want to move to the next step which is to make each "row" in my ListView launch the browser to the URL contained in the data, either by
(A) clicking anywhere in the row, or
(B) clicking a hyperlink displayed within the row data
For option (A), it appears that I need to have my onItemClick() method issue an intent that launches the browser. That's straightforward, but I don't get how to associate the URL with the item (currently its just one part of the string content for each "row" of text). How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL? Do I need to replace my String Array with an array of custom objects?
For option (B), can I use Linkify? It seems that my string array elements get converted to individual TextViews (inferring from the way the Toast text is generated in the HelloListView sample). Do I have access to that TextView to run Linkify against? Do I need to replace my String Array with a TextView Array and run Linkify myself? Am I completely off base?
Thanks to anyone who can help explain back to me what I'm trying to do, in a way that helps to find my way around the SDK, samples and other helps!
How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL?
Use a regular expression (java.util.regex) to find the URL.
For option (B), can I use Linkify?
Yes.
Do I have access to that TextView to run Linkify against?
Yes. Override getView() in your ArrayAdapter. Chain to the superclass and get your TextView from the result of super.getView().
Even better would be to use Linkify on your strings before putting them in the array in the first place.
Do I need to replace my String Array with a TextView Array and run Linkify myself?
No, and that is really not a good idea. Here is a free excerpt from one of my books that goes into more detail on tailoring the individual rows of a ListView, in case this helps.

Android TextViews. Is parametrization possible? Is binding to model possible?

I am new to both Android and Stack Overflow. I have started developing and Android App and I am wondering two things:
1) Is it possible to parametrize a TextView? Lets say I want to render a text message which states something like: "The user age is 38". Lets suppose that the user age is the result of an algorithm. Using some typical i18n framework I would write in my i18n file something like "The user age is {0}". Then at run time I would populate parameters accordingly. I haven't been able to figure out how to do this or similar approach in Android.
2) Let's suppose I have a complex object with many fields. Eg: PersonModel which has id, name, age, country, favorite video game, whatever. If I want to render all this information into a single layout in one of my activities the only way I have found is getting all needed TextViews by id and then populate them one by one through code.
I was wondering if there is some mapping / binding mechanism in which I can execute something like: render(myPerson, myView) and that automatically through reflection each of the model properties get mapped into each of the TextViews.
If someone has ever worked with SpringMVC, Im looking for something similar to their mechanism to map domain objects / models to views (e.g. spring:forms).
Thanks a lot in advanced for your help. Hope this is useful for somebody else =)
bye!
In answer to #1: You want String.format(). It'll let you do something like:
int age = 38;
String ageMessage = "The user age is %d";
myTextView.setText(String.format(ageMessage, age));
The two you'll use the most are %d for numbers and %s for strings. It uses printf format if you know it, if you don't there's a quicky tutorial in the Formatter docs.
For #2 I think you're doing it the best way there is (grab view hooks and fill them in manually). If you come across anything else I'd love to see it.

Categories

Resources