谁能解释这个问题; 什么是'R'之间的差异
R.id.myListView
Run Code Online (Sandbox Code Playgroud)
&
android.R.layout.simple_list_item_1
Run Code Online (Sandbox Code Playgroud)
这些2'R'不是同一类吗?
* Some people has down voted this question. I need to ask them the reason. If you answered the duplicate question & then down voted me it would have made sense. Neither answered my question nor the duplicate one!!! I mean whats the point of down voting some one without even helping? isn't this site supposed to be for help for programmers!! Weird!! **
我对 php 比较陌生,正在学习一个教程,其中有一个代码可以像这样向数组添加值:
$errors = array();
$errors[] .= 'You must enter a value';
Run Code Online (Sandbox Code Playgroud)
所以我对上面的代码感到困惑。
我知道我可以像下面这样向数组声明和添加值。
$myarr = array();
$myarr[]= "aa";
$myarr[]= "bb";
print_r($myarr);
Run Code Online (Sandbox Code Playgroud)
此外,我可以使用字符串连接运算符 (.) 附加字符串,如下所示:
$str = "val1"."val2";
Run Code Online (Sandbox Code Playgroud)
但是在向数组添加值之前放置连接运算符 (.) 有什么意义呢?
我有2个链接; 它给出了json数据.我试图从使用asynTask的android中的相同活动的url中获取值.做了编码,直到将数据转换为字符串(存储在jsonStr1中).但现在出现了问题.因为,在2个网址中:一个以JSON对象开头 -
{ "contacts": [ {"id": "c200", "name": "Ravi Tamada" },
{ "id": "c201", "name": "Johnny Depp" }
]
}
Run Code Online (Sandbox Code Playgroud)
另一个以JSON数组开头 -
[{"appeId":"1","survId":"1"},
{"appeId":"2","survId":"32"}
]
Run Code Online (Sandbox Code Playgroud)
现在,我将如何为他们提供一个条件,无论是知道它的JSON数组还是对象?JSON数组是我知道的对象,但无法找到如何分离它们.我试过以下:
JSONObject jsonObj = new JSONObject(jsonStr1);
if(jsonObj instanceof JSONArray){}
Run Code Online (Sandbox Code Playgroud)
但是如果condition显示错误不兼容的条件操作数类型JSONObject和JSONArray
class C3 {
public static int n = 0;
public int m = 0;
public C3() {
n++;
m++;
}
public void display() {
System.out.println(n + " " + m);}
}
}
Run Code Online (Sandbox Code Playgroud)
执行: -
C3 c1 = new C3();
c1.display();
C3 c2 = new C3();
c1.display();
c2.display();
Run Code Online (Sandbox Code Playgroud)
打印数字(输出)
1 1
2 1
2 1
Run Code Online (Sandbox Code Playgroud)
任何人都可以一步一步向我解释输出吗?我对第二行输出有点困惑,为什么m和n值都没有增加?也是在第3次输出为什么不从头开始?
我为spinner创建了一个自定义适配器类,它可以获取对象类型值.但奇怪的是它在代码中显示出一些错误.
SpinAdapter类
public class SpinAdapter extends ArrayAdapter<Country>
{
private Context context;
private Country[] values;
public SpinAdapter(Context context, int textViewResourceId, Country[] values)
{
super(context, textViewResourceId, values);
this.context = context;
this.values = values;
}
public int getCount(){
return values.length;
}
public Country getItem(int position){
return values[position];
}
public long getItemId(int position){
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView label = new TextView(context);
label.setTextColor(Color.BLACK);
label.setText(values[position].getName());
return label;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup …Run Code Online (Sandbox Code Playgroud) 我在我的活动背景中使用音乐.但是当我试图取消它时它不起作用.音乐一直在持续运行,直到它完成.以下是代码:
public class xx extends Activity
{ BackgroundSound mBackgroundSound = new BackgroundSound();
@Override
protected void onCreate(Bundle savedInstanceState)
{ ....
}
@Override
protected void onResume()
{
super.onResume();
mBackgroundSound.execute();
}
@Override
protected void onPause()
{
super.onPause();
mBackgroundSound.cancel(true);
}
Run Code Online (Sandbox Code Playgroud)
和选项菜单选择:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
mBackgroundSound.cancel(true);
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.menu_Add:
{ mBackgroundSound.cancel(true);
Intent intent = new Intent(xx.this,yy.class);
intent.putExtra("flag", "add");
intent.putExtra("AddObj", "mm");
startActivity(intent);
break;
}
case R.id.menu_list_quote:
{
mBackgroundSound.cancel(true);
Intent intent = new Intent(xx.this,zz.class);
intent.putExtra("Obj", "nn");
startActivity(intent); …Run Code Online (Sandbox Code Playgroud)