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);
Related
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 have a listview with radio buttons now i need to add one value from a edittext after typing some thing in the edittext the typed text should appear in the listview as next row.? how it is posible.?
ListView with simpleArrayAdapter :
Follow these steps it may help:
1. Fetch the value from edit text after the user types using gettext()
2. Insert this value in an array.
3. create a list view.
4. create an arrayAdapter with the already created array as source.
5. Now set the adapter with listview using (array variable).setAdapter(adapter name);
For every time the user updates use notifyDataSetChanged() to refresh your listview with the new contents.
Pseudo code:
onClick(){
array.add(editText.gettext());
adapter.notifyDataSetChanged();
}
Click here for more.
When normally populating a Spinner as I have done in the past I normally use a SpinnerAdapter then normally have items in resources to populate it.
I have currently though a different query, I have in my code a user input for an int and I want my spinner to populate with numbers up to the user selected number. So if the user enters the number '5' it is saved to an int variable. I then want the Spinner to show 1,2,3,4,5 as choices.
I am really not sure how I would approach this.
Thanks, Oli
Edited
Below is a basic example of how you would add Integers to your spinner :
mspin=(Spinner) findViewById(R.id.spinner1);
Integer[] items = new Integer[]{1,2,3,4};
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,android.R.layout.simple_spinner_item, items);
mspin.setAdapter(adapter);
You can refer to this and make changes in your project as per your logic. Also in your case you should use an ArrayList of integers since the number of choice of the user seems to be dynamic. you can create an arraylist and replace in for the Integer array in the above code.
Hope this helps!!
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
I have a String countries[].
now when i click a button then on the onClick event this abc array is filled.suppose it is filled with the name of 10 countries.These 10 countries should be visible as a list so that i can choose any 1 country among the list. but i am not able to show them as a list.
My programme crashes if i use the following code :
ListView list = (ListView)findViewById(R.id.ListView);
list.setAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_1, countries));
As countries is filled later on the click of a button.So initially the countries array is empty and as the onCreate() is executed first it crashes.
I found the examples on net where there is pre-defined array.so it works.My array is filled in a onClick event.how can i display List at that moment???
Make list your member variable.
Move the setAdapter call inside your onClick()....That'll do.