I want to display List of Contact Names with the respective phone numbers
like
Vikas Patidar <9999999999>
Rahul Patidar <9999999999>
using AutoCompleteTextView when a user type text in the mobile number field.
In default style I can only display the list of names.
Can anyone please tell me how can I implement this so that when a user select any item in list and I can display number of that in Mobile number field.
You need use adapter for this task. For example, with SimpleAdapter:
SimpleAdapter adapter = new SimpleAdapter(context, list, R.id.row_layout, new String[] { "Name", "Phone" }, new int[] { R.id.name, R.id.phone });
autoCompleteField.setAdapter(adapter);
For this you need make a layout XML file and list must be of type List<? extends Map<String, ?>. Strings in 4th parameter are keys for maps in list. Ints in 5th parameter are identifiers of components in layout file.
Or you can extend any adapter and use it. See this link for reference.
Related
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
The official Android docs say the following:
from A list of column names that will be added to the Map associated with each item.
to The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter.
I've accomplished this as follows:
final String[] from = new String[] {"TEXT1", "TEXT2"};
final int[] to = new int[] {android.R.id.text1, android.R.id.text2};
a = new SimpleAdapter(this, list, resource, from, to)
I'm able to set data in the view just fine, but im extremely confused as to why the from parameter is necessary. Why not just supply a list of xml resources? Why do a list of (column names?) need to be passed in as well?
Please help me understand.
The first N views in this list are given the values of the first N columns in the from parameter.
This means the values in the from parameter will be set in the corresponding views in the to parameter. According to the SimpleAdapter Android docs, if the views are TextViews, then a list of Strings is expected, and will be bound to the TextViews by calling setViewText(TextView, String).
I've been searching for a way to create a favorites list. Something like the expandable list view but instead of having fixed groups it should allow the user to add groups he desires. I use a HashMap<String, List<String>> for storing the subgroups and their Group's name. I also use a text file to load stored groups and subgroups.
Is it possible to reuse a List<String> to enter values into the HashMap. My multiple attempts have failed so I was wondering if there is a possible work around. This is basically what I did for my last attempt:
myList.add("Carrot");
myList.add("Cabbage");
myHash.put("Group1", myList);
myList.clear();
myList.add("Orange");
myList.add("Apple);
myHash.put("Group2", myList);
When I view the results on the emulator it displays Orange and Apple for both groups. Any suggestions would be appreciated since I don't program in java often.
myList.add("Carrot"); myList.add("Cabbage");
myHash.put("Group1", myList);
//replace clear to new object.
myList = new ArrayList();
myList.add("Orange"); myList.add("Apple);
myHash.put("Group2", myList);
I am creating an app that has several Buttons on the first screen. Every Button will parse a separate XML file and is supposed to create a nested list from that information.
All the XML files have this structure:
<blalist>
<house>
<name>Blaname1</name>
<eaddress>195 bla steet</eaddress>
<caddress>195 bla strasse</caddress>
<telephone>123456</telephone>
</house>
<house>
<name>Blaname2</name>
<eaddress>15 bla steet</eaddress>
<caddress>15 bla strasse</caddress>
<telephone>12345685</telephone>
</house>
</blalist>
After clicking the first button i would like to generate a ListView consisting out of only the names from tag "name". So the list should only show Blaname1,Blaname2...
After clicking on one of the names all the other tags should be displayed as content;
tags "eaddress","caddress","telephone" and three extra buttons.
Basically a 3 screens scenario. First page with the main buttons. Second page shows a list generated only with the names. Third screen shows the details of the specific name clicked.
How do i go about that? I found loads of info for parsing xml to ListView and some info about ExpandableListView but i couldnt really wrap my head around of how to go about this one. Please help!
All you need to do is parse your XML and structure the data in the format that is supported by the SimpleExpandableListAdapter class.
1) For groups
List<HashMap<String, String>> lstGroups
2) For sub items of groups
List<ArrayList<HashMap<String, String>>> lstGroupItems
and then you can use SimpleExpandableListAdapter
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
getApplicationContext(), lstGroups,
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key that will identify group in `lstGroups`.
new int[] { R.id.row_name }, // ID of each group item.-Data
lstGroupItems, // childData describes second-level
R.layout.child_row, // Layout for sub-level entries(second level).
new String[] { "Sub Item" }, // Keys that will identify child items in `lstGroupItems`
new int[] { R.id.grp_child }
);
setListAdapter(expListAdapter);
You can refer this example
Expandable ListView in ANDROID using SimpleExpandableListAdapter, a simple example.
Added :
I think you should use SQLiteDatabase if you are having large amount of data or else you can structure your data in the following format
Map<String, Map<String, String>> mapHouses;
Here the key will be the house name and its value will be again the Map which will hold the house properties and the corresponding value.
You will be requiring access to mapHouses accross diffrent activity so you can have the same in your application context i.e the Application class and pass the house name to the activity that neds to display the house details. But you will end up holding large data into the memory and which can be lost if your application is killed by Android.
Based on your comment in response to Vishal your question is actually asking how to build an entire application.
You need to build
a main activity with a button that launches your list activity
a list activity that displays a list of names
a detail activity that can be used to display the details associated with a name
In addition you'll need to decide on a technology you'll use to deserialize the XML and store it somehow. I'd recommend XStream to deserialize but there're loads of options and you may already have a preference.
Then you'll want to store the Name objects you've deserialized. I'd recommend that you use ORMLite or DB4O.
You'll need a way to load a list of all names and a way to load the details of a particular name from whichever persistence technology you've chosen.
Your best bet is to try and do those things and then post new questions about specific problems you have trying to build the application.
Hope that helps... and isn't just teaching grandma to suck eggs
i need to display four names continues in listview
for example
aravind
bose
guru
moorthy
aravind
bose
guru
moorthy
the set of values to be displayed in listview for "n" number of times
if i have mension 10times.the four names should be display for 10 times in listview.help me
for this you need to pass "n" as a parameter while calling your custom adapter.
Since its your custom adapter create your arrayList in the adapter to be used for the list view using the parameters of ArrayList(data to be displayed) and the "n". Using these create another arrayList which is used to display the listView data..
the call would be somewhat like this:
listAdapter = new CustomListAdapter(this, R.layout.list_view,
countryStringList, n);