public class HelloWorld {
public static void main (String args[]){
System.out.println ("Hello ");
http://www.google.com
System.out.println ("World!");
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码只是编译和执行正常.为什么编译器没有报告任何错误?
询问用户的哪个好地方,当他点击后退按钮时是否要退出应用程序?我考虑了onPause
和onStop
,但是只要应用程序在其他应用程序之后消失,这些方法就会触发.
更新:应用程序还应询问用户是否尝试从按钮(在应用程序本身)中退出应用程序,而不是后退硬键.
我是Android开发的新手.我试图通过使用SimpleAdapter填充一个微调器.但是微调器的列表显示空白元素.当我单击任何元素时,其文本在Toast中正确显示.请告诉我下面的代码中有什么问题.
public void onCreate(Bundle savedInstanceState) {
private List<Map<String, String>> data = new ArrayList<Map<String, String>>();
String[] from = new String[] { "colorsData" };
int[] to = new int[] { R.id.spinner };
String[] colors = getResources().getStringArray(R.array.colorsData);
for (int i = 0; i < colors.length; i++) {
data.add(addData(colors[i]));
}
Spinner spinner = (Spinner) findViewById(R.id.spinner);
SimpleAdapter simpleAdapter = new SimpleAdapter(this, data, android.R.layout.simple_spinner_item, from, to);
simpleAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(simpleAdapter);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(
parent.getContext(),
"Selected …
Run Code Online (Sandbox Code Playgroud) 初始化变量,特别是类级别的对象引用是一个好习惯吗?请考虑以下示例;
public class MyClass {
private static MyObject myObject;
public static void main(String[] args) {
myObject = new MyObject();
}
}
Run Code Online (Sandbox Code Playgroud)
要么
public class MyClass {
private MyObject myObject = new MyObject();
public static void main(String[] args) {
// Other code
}
}
Run Code Online (Sandbox Code Playgroud)
哪种方式最好?请指导我们两者的利弊.
问候.
我的SDK中有默认(随附SDK)和三星Galaxy Tab模拟器.我想知道其他第三方(摩托罗拉,LG,夏普等)模拟器是否可用,以便我可以测试我的应用程序以获取更多设备.请提供带有链接的名称.
我正在开发一个基于测验的应用程序,当用户点击任何选项时,它应该是一个合适的消息,例如"你的ans是正确的","你的ans是错的".我想要的是
1. how to display that sort of messages ?or is it the only way to display such msgs ?
2. If the user clicks wrong option the it should show the correct answer as well as the msg
here is what i have done so far but its not working giving force close!!!
public void onClick(View v)
{
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.button1:
Log.d("ERR", v.getTag().toString());
if (v.getTag().toString().equalsIgnoreCase("right"))
{
displayAnswer();
}
else
{
errorAnswer();
} …
Run Code Online (Sandbox Code Playgroud)