arraylist

How to bind ArrayList Objects to android GridView?

给你一囗甜甜゛ 提交于 2019-12-23 04:13:09
问题 I've a collection of array list objects like: ArrayList<Person> persons=new ArrayList<Person>(); so how can i bind this list of objects persons to android gridview ? 回答1: GridView settingGrid; ArrayList<Person> persons; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.setting); persons =new ArrayList<Person>(); settingGrid = (GridView)findViewById(R.id.settinggridview); settingGrid.setAdapter(new SettingImageAdapter(this));

Tutorials for Java errors and syntax

↘锁芯ラ 提交于 2019-12-23 03:53:06
问题 I am asking for help on self-help, which is kind of an oxymoron. How do I bug you nice folks less by solving more of my own problems? I am in my last week of Java programming and I am having a huge hurdle with learning Java. I have read all the books but I keep getting hung up on tiny little issues. It is like trying to build a house of cards. I only know about the parts of the syntax and the uses that the book shows. When I am combining things, I run into horrible hurdles. I try for hours of

java实例 之 斗地主

这一生的挚爱 提交于 2019-12-23 03:44:55
需求分析 准备牌: 完成数字与纸牌的映射关系: 使用双列Map(HashMap)集合,完成一个数字与字符串纸牌的对应关系(相当于一个字典)。 洗牌: 通过数字完成洗牌发牌 发牌: 将每个人以及底牌设计为ArrayList,将最后3张牌直接存放于底牌,剩余牌通过对3取模依次发牌。 存放的过程中要求数字大小与斗地主规则的大小对应。 将代表不同纸牌的数字分配给不同的玩家与底牌。 看牌: 通过Map集合找到对应字符展示。 通过查询纸牌与数字的对应关系,由数字转成纸牌字符串再进行展示。 代码实现 package com . Map ; import java . util . * ; public class Doudizhu { public static void main ( String [ ] args ) { doudizhu ( ) ; } private static void doudizhu ( ) { String [ ] hua = { "♠" , "♥" , "♦" , "♣" } ; String [ ] shu = { "2" , "A" , "K" , "Q" , "J" , "10" , "9" , "8" , "7" , "6" , "5" , "4" , "3" } ; Map < Integer , String > map = new HashMap

Sorting objects in an ArrayList without using Collections.sort

孤人 提交于 2019-12-23 03:23:28
问题 I would like to use my own sorting method instead of Collections.sort so that I can tinker around with my program to understand other sorts, generics, and ArrayList s better. I have an employee class that has an employee number member. I know how to make an ArrayList of Employee objects, but could you explain how I could print and sort them? I started off by sorting a regular array and wanted to do the same with an ArrayList of Employee objects (the employee number). I'm having trouble

How to speed up large data insertion in Database (SQLite) in Android application

假装没事ソ 提交于 2019-12-23 03:14:28
问题 I have a situation where I have to insert data in the database, and the data is very large which is in an ArrayList . The data is inserted in a loop like this: for( ..... ) ContentValues cv = new ContentValues(); // cv.put statements sqLiteDB.insert ...... Now it takes around more than 1 minute in the test case and is expected to exceed 10 minutes with real data, while the target is to keep the time below 30 seconds. Data cannot be reduced. My questions are: How to improve the speed Is there

Compare a Dynamic ArrayList with ArrayList! and remove the elements which are not present in Dynamic array

亡梦爱人 提交于 2019-12-23 02:52:50
问题 I have two ArrayLists , contactModels and list . The contactModels is a Dynamic Arraylist, I need to compare the two list and remove the elements in list , which are not present in contactModels (DynamicArrayList). I tried nested loops, and this: for (int i = 0; i < list.size(); i++) { if(!contactModels.get(i).getEmpID().equals(list.get(i).getEmpID())) { databaseadapter.removeContact(contactModels.get(i)); } } But I can't achieve it. 回答1: you are not testing whether an item in contactModels

Throwing null pointer exception in Android

眉间皱痕 提交于 2019-12-23 01:55:34
问题 I'm trying to fetch an audio file from the audio directory, for that I'm using below code. I'm not able to figure out why this condition if (home.listFiles(new FileExtensionFilter()).length > 0) is throwing an error. Code is given below. Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; final String MEDIA_PATH = allsongsuri.toString(); private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>(); public ArrayList<HashMap<String, String>>

How to Add newline after every 3rd element in arraylist in java?

家住魔仙堡 提交于 2019-12-23 00:29:18
问题 My program need to add newline after every 3rd element in the arraylist. Here is my input file which contain the following data: 934534519137441534534534366, 0796544345345345348965, 796345345345544894534565, 734534534596544534538965 , 4058991374534534999999, 34534539624, 91953413789453450452, 9137534534482080, 9153453459137482080, 405899137999999, 9653453564564524, 91922734534779797, 0834534534980001528, 82342398534 6356343430001528, 405899137999999, 9191334534643534547423752,

How to Add newline after every 3rd element in arraylist in java?

孤人 提交于 2019-12-23 00:29:05
问题 My program need to add newline after every 3rd element in the arraylist. Here is my input file which contain the following data: 934534519137441534534534366, 0796544345345345348965, 796345345345544894534565, 734534534596544534538965 , 4058991374534534999999, 34534539624, 91953413789453450452, 9137534534482080, 9153453459137482080, 405899137999999, 9653453564564524, 91922734534779797, 0834534534980001528, 82342398534 6356343430001528, 405899137999999, 9191334534643534547423752,

ArrayList<ArrayList<String>> in Parcelable object kotlin

隐身守侯 提交于 2019-12-22 22:06:07
问题 Array of arrays of strings needs to be parcelized. The object is like so data class Foo ( @SerializedName("bar") val bar: ArrayList<ArrayList<String>>, ) It doesn't exactly need to be ArrayList. Array can also used. data class Foo ( @SerializedName("bar") val bar: Array<Array<String>>, ) Whichever easier is ok to map this json data { "bar": [ ["a", "b"], ["a1", "b2", "c2"], ["a3", "b34", "c432"] ] } Using kotlin experimental Parcelize crashes the app when it's compiled with progaurd How is it