Android - using Adapter with object - android

I have an object called "EntityType en" which contains a string "Name" i want to use Array Adapter to check the index of the given object but without defining my list in the R.layout because it is defined in by the object.
What I am trying to do is showing my data (array) in a menu dialog that lets the user select the desired "Name".

Related

Andorid how can i add value inside of Documents array

i try to add a Map item to a certain position of my Array. To do so i tried this code:
String userid =FirebaseAuth.getInstance().getCurrentUser().getUid();
DocumentReference washingtonRef = db.collection("Users").document(userid);
// Atomically add a new region to the "regions" array field.
washingtonRef.update("shoppingLists[0]", FieldValue.arrayUnion("greater_virginia"));
}
Here is the structure where i have to add a value:
At this point i have to add the value
You can't index into array fields like this with Firestore. You can add or remove elements of an list type field by value using arrayUnion and arrayRemove, but you can't specify where that item is in the array. If you need more control over the order of the elements in the array, you will have to read the document first, modify the array in memory, then update that field back into the document.

Showing only one parameter of custom object in dropdown menu using AutoCompleteTextView

I want to show only one parameter from object(s) found using AutoCompleteTextView. I have list of custom items and I'm using this list in ArrayAdapter which is used in my AutoCompleteTextView. But as I find item by typing something to AutoCompleteTextView, only object as whole is shown (Object type and some identifier), but I want to show just Objects attribute "name" which is a String.
The way i'd go about this is making a separate arraylist with all the names inside of it. Display that and get the user to chose from there, once they have use the index to find the object in the other list.
Initiate new string array
String[] data = new String[1]); // terms is a List<String>
for(int i=0;i<=1;i++){ //only the 1st position of ur data getting inserted
data[0]=s.get(i).toString();
}
ArrayAdapter<?> adapter = new ArrayAdapter<Object>(activity, android.R.layout.simple_dropdown_item_1line, data);
keywordField.setAdapter(adapter); // keywordField is a AutoCompleteTextView

Emptying Parse.com Array field in android

I have created a Parse.com class in which a field type is Array. I save List with the following code:
public void setPreperties(List<String> properties){
put("properties", properties);
}
The are two senarios:
Users will either select one or more properties
Or they will select no properties at all.
If the user has selected properties, its saved with the above code.
When the user deselectes all the properties and click save, I pass null to the above method to save. But this gives NullPointerException.
My question is how can I save empty data in the Array?
Try passing an empty list, like Collections.emptyList() or new ArrayList<String>().

android listview issue with more than 3 dynamic data

I have a doubt. I have 3 array list dynamic values. I need to display these dynamic values in a listview. can someone please tell me how can i achieve this.
I have name[] array, status[] array and image[] array. I need to dynamically display the values in listview in a android sample
This is what i have:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,NameList);
In this i am able to display i am able to display all the names in NameList[].
An array list only accepts an array of values, so as you see, you can only pass in the names. You have two options,
The simple option is to create a compound object, say Person, that has a name, status, and image. Then you create a Person[], and create the array list on that, and pass it into the array adapter. You must implement Person.toString() to print out the Person object as you'd like.
If you need to be able to lay out the Person fields in a more flexible way then you could simply by implementing toString() on Person, you need to create a custom list adapter. You can take a look at this post to get you started,
Categorise the listview

how to generate dynamic data for an item in listview

I have created a list activity calles as Category List to show a list of category dynamically from web by parsing an XML file. The XML file contains values "ID"(id of the particular category) and "title"(category name). So what I've done is, I've parsed the XML file and collected the ID and title to an ArrayList called categries using SAX parser.
In the list activity, I have a created a new string array and added the title of each category to it. The thing I want to do is to assign the category id to each category shown in the list view and to use the id to get the appropriate view for that category. Is there any way to assign an id to the each of the list items.
regards
dj
Introduce a JavaBean, and fill it:
class YourBean {
private int id;
private String title;
// add get / set methods
}
Create the list and put it in a ArrayList ,then fill a Adapter with it.
Then, you can use an http://developer.android.com/reference/android/widget/ArrayAdapter.html and in your onClicked etc method use mAdapter.getItem(int). That's in very short words.
Take a look in the SDK examples.

Categories

Resources