arraylist

Saving/Restoring custom ArrayList on Android screen rotate?

北慕城南 提交于 2020-01-03 04:43:26
问题 I have a custom ArrayList of MovieItems that I want to save and restore on screen rotation. I checked out this post - How to save custom ArrayList on Android screen rotate? - and implemented and adapted some of the codes but the saving and restoring don't seem to be working for me. 1) Saving the ArrayList: public List<MovieItem> mItems = new ArrayList<>(); @Override public void onSaveInstanceState(Bundle outState) { outState.putParcelableArrayList(MOVIE_KEY, (ArrayList<? extends Parcelable>)

String array list display problem

試著忘記壹切 提交于 2020-01-03 04:34:35
问题 I have create to String array one is "word" another is "sentence". <resources> <string-array name="word"> <item> the</item> <item> a</item> <item> is</item> <item> you</item> <item> to</item> </string-array> <string-array name="sentence"> <item> the little boy</item> <item> a good boy</item> <item> is about me</item> <item> then you give</item> <item> was to come</item> </string-array> </resources> Now i am trying access these two string array from the java code. which is final String words [

How to store ArrayList<LatLng> on Sqlite database?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 03:38:04
问题 I'm developing an app that tracks user movement. On each onLocationChanged() I store the latitude and longitude in ArrayList<latLng> and than draw a polyline on the route. Now, when activity stopped I want to save all users activity information like: distance average pace duration all ArrayList latlng points of activity on Sqlite database to restore it later and draw a polyline with this points. The problem that I have no idea how to store the ArrayList of latitude and longitude to the

Populate ListView with an arrayList<String> with data obtained from a cursor

孤人 提交于 2020-01-03 03:33:08
问题 Helo i am trying to populate a listView with data stored in a sqLite. After i select a product i want all the reference of that product to go on the same line like i drew in the picture. Can i make the ArrayAdapter put all records in the same xml? My code looks like this: The cursor that returns all records: public Cursor getAllRows() { String where = null; // query the DBAdapter Cursor cursor = db.query(true, TABLE_NAME, ALL_KEYS, where, null, null, null, null, null); if (cursor != null) {

ArrayList null pointer exception

丶灬走出姿态 提交于 2020-01-03 03:17:08
问题 I have created an arraylist, and a ListView. I intend to iterate through the ListView, and checking whether they are checked or not, and then add the object (using ListView.getItem()) to my arraylist. however I get a NullPointerException. The ArrayList people_selected, is declared at top of class like this: ArrayList<PeopleDetails> selected_people; And my code: for (int i = 0; i < people_list.getCount(); i++) { item_view = people_list.getAdapter().getView(i, null, null); chBox = (CheckBox)

Using ArrayList to store variables

社会主义新天地 提交于 2020-01-03 02:49:19
问题 I'm coding a project to store an array of objects, probably in an arraylist. So, my object has data elements, getters and setters. I do not have an idea how to access the elements of the object. For example my object is a book which has the following data elements. Book ->Author ->Price ->Date If the price of a certain book changes, how do I update the arrayList? Do I need a 2d arrayList? I think indexOf would not work because it is an object? Not really sure. I'm just a newbie in programming

Lists double their space in c# when they need more room. At some point does it become less efficient to double say 1024 to 2048?

非 Y 不嫁゛ 提交于 2020-01-02 23:11:06
问题 When numbers are smaller, it's quick to grow the size of an array list from 2 to 4 memory addresses but when it starts to increase the amount of space closer to the max amount of space allowed in an array list (close to the 2MB limit). Would changing how much space is allotted in those bigger areas be more efficient if it was only growing the size of the array by a fraction of the size it needs at some point? Obviously growing the size from 1mb to 2mb isn't really a big deal now-days HOWEVER,

Android set Arraylist data to custom adapter

怎甘沉沦 提交于 2020-01-02 20:47:15
问题 I have an ArrayList<String> statusListTextOnly; that contains some tweets. Now if I use it like this i.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, statusListTextOnly)); Everything is fine, the activity starts and the tweets show in listview. But I wanted to go deep in my app, I want to use custom adapter. So I did: Tweet[] tweets; TweetAdapter adapter; Tweet weather_data[] = new Tweet[] { new Tweet(statusListTextOnly) }; adapter = new

Remove even numbers from an ArrayList

烈酒焚心 提交于 2020-01-02 20:26:08
问题 I have to create a method which has an ArrayList; I need to remove even numbers from this ArrayList. I have written code for that but there is a logical error which I couldn't identify. Here is my code: static void sortList(){ List <Integer> number=new ArrayList <Integer>(); number.add(11); number.add(45); number.add(12); number.add(32); number.add(36); System.out.println("Unsorted List: "+number); for (int i=0;i<number.size();i++){ int even=number.get(i)%2; if (even==0){ System.out.println(

Java 2D array into 2D ArrayList with stream

吃可爱长大的小学妹 提交于 2020-01-02 13:44:32
问题 So I have an Integer[][] data that I want to convert into an ArrayList<ArrayList<Integer>> , so I tried using streams and came up with the following line: ArrayList<ArrayList<Integer>> col = Arrays.stream(data).map(i -> Arrays.stream(i).collect(Collectors.toList())).collect(Collectors.toCollection(ArrayList<ArrayList<Integer>>::new)); But the last part collect(Collectors.toCollection(ArrayList<ArrayList<Integer>>::new)) gives me an error that it cannot convert ArrayList<ArrayList<Integer>> to