Tag: java的

搜索标记从编辑文本在地图片段android

对不起,我刚开始学习编程。 我在我的应用程序中制作了地图活动,并且有一个搜索框来查找我之前制作的标记。 我的问题是如何在搜索框中的地图活动中找到标记? 我没有使用数据库,我逐个制作了一个标记,因为它在我的地图中只有10个标记。 这里是我在数组中的所有标记 Double [] lat = { -7.362366, -7.363552, -7.360093, -7.384362, -7.371319, -7.369428, -7.342803, -7.364069, -7.361312, -7.368688, -7.358674, -7.369610, -7.366610, -7.371556, -7.348831, -7.362575 }; Double [] lon = { 108.545943, 108.542081, 108.605078, 108.533789, 108.528442, 108.483738, 108.553713, 108.581835, 108.533522, 108.534660, 108.639087, 108.540899, 108.561781, 108.525056, 108.633850, 108.537306 }; String [] nama ={ “Situ Mustika”, […]

AsyncTask / Handler滞后UI

所以我有这个从网站获取数据的AsyncTask,在它的post执行后,它调用main函数将setText作为main的textview。 这是代码。 @Override protected Void doInBackground(String… arg0) { result = connect(start);//connect to the webpage, start is a URL // TODO Auto-generated method stub return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); Document doc = Jsoup.parse(this.result); Elements stuff = doc.select(“td”); MainActivity.GetData(doc);//set the textview } 我叫处理程序每​​五秒钟执行一次,这是处理程序代码。 hand = new Handler(); r = new Runnable() { […]

如何多次动态注入LinearLayout(Android)?

好的,我制作了一个包含+和 – 按钮的XML Layout文件,以及一个textView,我可以使用以下方法将它注入我的LinearLayout: LinearLayout myLayout = (LinearLayout)findViewById(R.id.linearLayout2); View injecterLayout = getLayoutInflater().inflate(R.layout.newplayerlayout, myLayout, false); myLayout.addView(injecterLayout); 但我希望能够多次注入它,所以我有几个+, – ,而textView有什么方法可以做到这一点?

找到n个数字的GCD

我正在尝试编写一个简单的程序,要求输入5个数字并输出它们的GCD。 我已经用一个简单的方法发现了如何用两个数字做到这一点: private static int gcd(int number1, int number2) //Finds GCD of 2 numbers. { if(number2 == 0) { return number1; } return gcd(number2, number1%number2); } 返回语句中的实际数学虽然令我感到困惑,但我不确定如何用5个甚至更多的数字写出来。 我听说以递归方式执行此方法,例如“gcd(a,b,c)= gcd(gcd(a,b),c)”是最好的方法,但我想我实际上遇到了麻烦有问题的数学逻辑。 我只需要一个很好的起点,真的,如何返回3个数字,然后是4个,然后是5个等等。我想一旦我得到逻辑部分,我就会明白如何更容易地做到这一点。

在Android 6.0中的Play商店中不要求更新apk的权限

我已经有应用程序在Play商店。我最近在Play商店添加了新的apk。 以前我为位置,相机和联系人添加了3个权限(我以数组格式添加)。 if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.MANAGE_DOCUMENTS) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION , android.Manifest.permission.MANAGE_DOCUMENTS, android.Manifest.permission.WRITE_EXTERNAL_STORAGE , Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.CALL_PHONE , Manifest.permission.READ_SMS, […]

当我从我的应用程序按下按钮时,Countdowntimer如何继续在后台运行?

我的计时器代码是: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initializer(); fire.setOnClickListener(this); } private void initializer() { minute = (EditText) findViewById(R.id.etMinute); seconds = (EditText) findViewById(R.id.etSeconds); fire = (Button) findViewById(R.id.bFireTimer); Remain=(TextView)findViewById(R.id.tvRemain); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bFireTimer: min=minute.getText().toString(); sec=seconds.getText().toString(); int MIN= Integer.parseInt(min); int SEC=Integer.parseInt(sec); long TIME= (MIN*60)+SEC; timercount = new MyCount(TIME * […]

异步写入GAE数据存储区

在我的Java应用程序中,有时我的用户会做一些需要数据存储区写入的工作,但我不想让用户在数据存储区写入时保持等待。 我希望在数据存储在后台时立即向用户返回响应。 似乎相当清楚我可以通过使用GAE任务队列来执行此操作,将任务排入队列以存储数据。 但我也看到有一个Async数据存储区API,看起来它比处理任务队列要容易得多。 我可以调用AsyncDatastoreService.put()然后从我的servlet返回吗? 该API会存储我的数据而不让用户等待吗?

Android:用Button更新UI?

所以我有一些简单的代码,但它似乎没有工作..任何建议? 我只想在按下按钮后显示图像,然后在2秒后变为不可见。 button.setOnClickListener(new OnClickListener() { public void onClick(View v) { firstImage.setVisibility(ImageView.VISIBLE); // delay of some sort firstImage.setVisibility(ImageView.INVISIBLE); } } 图像永远不会显示,它总是保持不可见,我应该以另一种方式实现吗? 我尝试过处理程序..但它没有用,除非我做错了。

Java算法填充单元格,如“Android – Flow”游戏

我有一个问题。 我们有一个表2xN ,其链接节点为1,6 -> 1,1和2,6 -> 2,1就像一个cilinder。 —————————————————– (1)->| 1,1 | 1,2 | 1,3 | 1,4 | 1,5 | 1,6 | -> (1) —————————————————— (2)->| 2,1 | 2,2 | 2,3 | 2,4 | 2,5 | 2,6 | -> (2) —————————————————— 我有一个StartPoint1 – 是单元格1,1一个点和单元格2,6 EndPoint1 和一个StartPoint12 – 是单元格2,1一个点和单元格2,5 EndPoint2 我想在路上找到两个填充所有表格的组合。 例如上面是 (P1)=(1,1) – >(1,2) – >(1,3) […]

将JSON解析为自定义ArrayList,仅返回最后一项?

我发现这有点奇怪,我正在从我的/ assets文件夹中的文件解析一些JSON。 我已经设置了一个自定义ArrayList。 现在,当我尝试将ArrayList中的数据添加到listview或spinner(Same adapter)时,它只显示最后一项。 这是我的代码: 我的解析方法: public ArrayList parseJSON(String json) { ArrayList shop = new ArrayList(); ShopName item = new ShopName(); Log.d(TAG, json); try { JSONArray jArray = new JSONArray(json); for (int i=0; i < jArray.length();i++) { JSONObject jObject = jArray.getJSONObject(i); item.setFromCurrency(jObject.getString("from")); item.setToCurrency(jObject.getString("to")); item.setRate(jObject.getString("cost")); data.add(item); } } catch (JSONException jen) { jen.printStackTrace(); } return […]