基本上我有一个位置的ArrayList:
ArrayList<WorldLocation> locations = new ArrayList<WorldLocation>();
Run Code Online (Sandbox Code Playgroud)
下面我称之为以下方法:
.getMap();
Run Code Online (Sandbox Code Playgroud)
getMap()方法中的参数是:
getMap(WorldLocation... locations)
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我不确定如何将整个列表locations传入该方法.
我试过了
.getMap(locations.toArray())
Run Code Online (Sandbox Code Playgroud)
但getMap不接受,因为它不接受Objects [].
现在,如果我使用
.getMap(locations.get(0));
Run Code Online (Sandbox Code Playgroud)
它会完美地工作......但我需要以某种方式传递所有位置...我当然可以继续添加locations.get(1), locations.get(2)等等但是阵列的大小各不相同.我只是不习惯整个概念ArrayList
最简单的方法是什么?我觉得我现在不想直接思考.
嘿,我正在构建一个基本的应用程序,包括文本,网址,图片和一些按钮.当您创建新项目时,您通常会选择哪种构建版本?最高,2.2?还有什么最小的SDK版本你选择?还2.2?还是最低的?
我对所有客户的最佳选择感到困惑
-谢谢!
这就是我到目前为止......它只是在应用程序打开时启动:
package com.android.countdown;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;
public class countdown extends Activity {
TextView mTextField;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextField = (TextView) findViewById(R.id.timer1);
new CountDownTimer(100000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("Seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("Finished");
}
}.start();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我需要调用start()一个按钮程序.但是,如果我.start()从它的位置移动new CountDownTimer(100000 , 1000) {得到一个错误.
嘿所有,我正试图让我的CountDownTimer在时间到零后自动恢复到原来的时间.就像一个无限循环.这是我到目前为止的代码(总共有3个计时器):
package com.android.countdown;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class countdown extends Activity {
public String formatTime(long millis) {
String output = "00:00";
long seconds = millis / 1000;
long minutes = seconds / 60;
seconds = seconds % 60;
minutes = minutes % 60;
String secondsD = String.valueOf(seconds);
String minutesD = String.valueOf(minutes);
if (seconds < 10)
secondsD = "0" + seconds;
if (minutes < 10)
minutesD = "0" + minutes; …Run Code Online (Sandbox Code Playgroud) 嘿大家,我正在尝试在我的网站上添加某种类型的评论系统,以便我在主页上发布新闻.我想要它做的是有任何人评论它(他们不需要登录).评论提交表单只需要一个名称和评论.最简单的方法是什么?让它显示当前新闻帖中有多少评论也是很好的.我不需要任何花哨的东西.谢谢!
嘿所有,所以基本上我有一个非常简单的布局与标题图像,主要居中的文本区域.以及位于主中心文本区域左侧的侧边栏.这基本上就是我的布局看起来如何:
<center>Header</center>
<div style="float:left;">Sidebar</div>
<center>Main Area</center>
Run Code Online (Sandbox Code Playgroud)
好吧,侧边栏显然会一直对齐到页面的左侧,我希望它做的仍然是在页面的左侧,但我希望它"拥抱"主要居中区域.
这里是什么样子,现在一个基本的图片,我想发生什么箭头: http://img18.imageshack.us/img18/2307/exampleps.jpg
我有一种方法可以为vehicles阵列增加一辆新车(本田).该阵列最多包含4辆车.
Vehicle[] vehicles = new Vehicle[4];
Run Code Online (Sandbox Code Playgroud)
如果存在值,则该方法应该将1个新Vehicle对象添加到vehicles数组的末尾null.问题是它正在写入null数组中的所有值,而不是只写入1然后踢出for循环.
这就是我所拥有的(注意 - 我需要使用数组代替ArrayList):
public void addVehicle(Vehicle Honda[]) throws FileNotFoundException
{
boolean found = false;
if(canAddVehicle() == true)
{
for(int i = 0; i < vehicles.length || !found; i++)
{
if(vehicles[i] == null)
{
Scanner reader = new Scanner(file);
Honda[i] = new Vehicle();
Honda[i].readRecord(reader);
vehicles[i] = Honda[i];
reader.close();
found = true;
}
}
System.out.println("Vehicle Added!");
}
}
Run Code Online (Sandbox Code Playgroud)
我设置found = …
好吧,所以这段代码就在Android开发者网站上,该网站设置ImageView为Bitmap:
class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference;
private int data = 0;
public BitmapWorkerTask(ImageView imageView) {
// Use a WeakReference to ensure the ImageView can be garbage collected
imageViewReference = new WeakReference<ImageView>(imageView);
}
// Decode image in background.
@Override
protected Bitmap doInBackground(Integer... params) {
data = params[0];
return decodeSampledBitmapFromResource(getResources(), data, 100, 100));
}
// Once complete, see if ImageView is still around and set bitmap.
@Override
protected void onPostExecute(Bitmap bitmap) { …Run Code Online (Sandbox Code Playgroud) 我可以成功计算短语中的单词数量,如:
int numWords = "I am testing".split(" ").length;
Run Code Online (Sandbox Code Playgroud)
(它返回3.)
但是,我得到一个用户输入并将其存储在一个字符串中,然后尝试计算其中的单词数,但它总是返回1,无论如何.
我正在stringVariable = scanner.next();使用和使用用户输入
int numWords = stringVariable.split(" ").length;
Run Code Online (Sandbox Code Playgroud)
获得单词数量.假设我输入"我正在测试".它会返回1.这是为什么?
我试图将带有公司徽标的“签名”附加到调用 mail() 函数时发送的消息的底部。这是我拥有的 HTML/PHP:
$message = '<html>
<body>'
. $_POST['message'] .
'<BR><HR><BR>
<img src="http://www.mysite.com/images/logo.gif">
</body>
</html>';
Run Code Online (Sandbox Code Playgroud)
例如,当您单击发送到 gmail 的电子邮件时,会出现一个对话框并显示
Images are not displayed. Display images below - Always display images from person@mysite.com
我希望签名图像只显示而无需单击对话框中给出的选项之一。来自其他人的电子邮件签名显示,但不显示该对话框。有没有办法让我做同样的事情?
如果用户每次都必须单击该选项才能显示我的签名,那真是太烦人了。
嘿所有,所以我有一个开始和一个停止按钮.我想要发生的是,一旦单击开始按钮,它就会消失并且停止按钮会显示在开始按钮的位置,以便能够单击停止按钮.这是由switch语句完成的吗?
//Start Button
btnstart.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
...
}
});
//Stop Button
btnstop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
...
}
}
});
Run Code Online (Sandbox Code Playgroud)