I have string like this :
you
me
i
me
i
i
you
me
me
I want to group that string in my ListView like this :
you (2)
me (4)
i (3)
and if I click "you (2)", show ListView again like this :
you
you
Can you help me?
First you need to sort your list adapter. For sorting this will be useful for you http://www.anddev.org/code-snippets-for-android-f33/alphabetical-listview-in-android-t56983.html
Then implement expandable list
As Dheeresh Singh said, please work on some code and then we can help more. Thanks
Related
i want to make a AutoCompletionTextView show suggestions
the behavior is to look in the data which is the ArrayAdapter and make suggestions
suggestions list will be a list of all texts that have the same sequence of characters
like i type abc and the data list have [ abc , fabc, geabcr, fgkd, abcg, meow]
and the suggestions will be [abc, fabc, geabcr ,abcg](see all suggestions have abc in them)
I have custom ListView in my android application. It consists images and title and content like subtitle and price. Here I want to sort my ListView in price basis. Any one can help me? How to sort the ListView. For example pls refer the following link if possible to sort the list in degree basis...
http://www.codeproject.com/Articles/507651/Customized-Android-ListView-with-Image-and-Text
You need to sort the data structure before setting in the listview. it is only the possible way i think
First sort your data like this
Collections.sort(myList, new Comparator<WeatherData>() {
#Override
public int compare(WeatherData lhs, WeatherData rhs) {
return lhs.degree.compareTo(rhs.degree);
}
});
and then apply it to your adapter.
I have a control Gridview and an XML that must populate the GridView.
XML is:
<?xml version='1.0' encoding='iso-8859-1' ?>
<MEDS>
<MED>
<NOM>GELOCATIL</NOM>
<COD>12812931</COD>
</MED>
<MED>
<NOM>OTRO GELOCATIL</NOM>
<COD>1281293222</COD>
</MED>
</MEDS>
How do I create a Cursor for this? Or alternatives, pls?
Bye.
gridViewObj.setListAdapter(Adapters.loadAdapter(this, R.xml.contacts));
gridViewObj : GridView Object
xml source : R.xml.contacts
[for More info click here][1]
[1]: https://developer.android.com/resources/samples/XmlAdapters/index.html
I think the right answer is to do an adapter class specific for this xml. But it is more complicated and takes more time. #Sravan has not provided the code so I am obliged to give this answer as right.
We can look for a creative and easy solution although not optimized.
If the case is that you only need 1 or 2 fields of the XML, which can be usual, because you're showing a list that is clickable, so you need only to show to title and to give a substantial information (id for example or use the text of the title itself) so that when you click, takes you to another activity.
So the easiest is to use an ArrayAdapter, a TreeMap and an ArrayList
TreeMap<String, String> xmlMapping;
//here you add the values of the xml with Xpath to the variables clave and valor
xmlMapping.put(clave,valor);
ArrayList<String> lista=new ArrayList<String>();
for(Map.Entry<String, String> entry: xmlMapping.entrySet())
{
lista.add(entry.getKey());
}
ArrayAdapter ad=new ArrayAdapter<String>(this.activity.getApplicationContext(),
R.layout.gridrow,R.id.colName,
lista);
grid.setAdapter(ad);
Then to know which element has been clicked the only thing is to iterate through the xmlMapping or take the value of the ArrayList.
How can I 'check' list of items in listview within my code ( not by user)
ProcessList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,nameList ));
ProcessList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
for example like ProcessList.(check these items...)
Just like we get items 'checked' by user from: ProcessList.getItemAtPosition(position);
Pls also suggest me anyother way..
Call setItemChecked() on the ListView for each position to be checked.
Also, please grow up. Badgering people on Twitter minutes after you post a question on StackOverflow is infantile. This is a volunteer resource -- if you require answers to questions in under an hour, hire a consultant.
Hey. I have the following code:
final String text = (String) lt.getItemAtPosition(position);
db.removeCategory(text);
What I want to do is to remove a item from a ListView. The problem I have is that I only can remove the item that is in the first position of the list.
Is like the getItemAtPosition(0);
Why's that? Can somebody help?
Thanks
Bind your array to ArrayAdapter and use its remove method to remove particular object. Refer this link to get some understanding of how it works.
Remove ListView items in Android
Why don't you add items into a collection or data datable and then bind it to ListView.
In ste removal phase you delete the item from the collection/data table instead direct one from the ListView.