我是新手,我已经开始学习python,但我有一些我无法理解的问题,
嗨我有这样的事情:
saved = getSharedPreferences("searches", MODE_PRIVATE);
String[] mystring = saved.getAll().keySet().toArray(new String[0]);
Run Code Online (Sandbox Code Playgroud)
为什么我们需要new String[0]内部的论证toArray?
我正在学习android,当然我是新手,我总是阅读类似于视图层次结构的东西,那究竟是什么意思呢?什么是视图层次结构?例如
//片段包含的框架不存在.片段//可能仍然是从其保存状态创建的,但是//没有理由尝试创建其视图层次结构,因为它//将不会显示.注意这不是必需的 - 我们可以//只运行下面的代码,我们将创建并返回//视图层次结构; 它永远不会被使用.
http://developer.android.com/reference/android/app/Fragment.html
我有一个像这样的代码:
public class CannonView extends SurfaceViewimplements SurfaceHolder.Callback{
Activity activity;
Run Code Online (Sandbox Code Playgroud)
它的构造函数:
public CannonView(Context context, AttributeSet attrs){
Super(context,attrs)
activity = (Activity) context;
Run Code Online (Sandbox Code Playgroud)
但显然AttributeSet什么也没做,我不知道为什么会这样,所以我的问题是:1.什么是AttributeSet?2.为什么我们需要提供AttributeSet attrs作为第二个参数?顺便说一下,其余代码用于使用画布进行绘画.谢谢.
我在实现此代码时遇到问题在Android中保存和读取内部存储器中的位图/图像
保存和检索我想要的图像,这是我的代码:
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
File mypath=new File(directory, + name + "profile.jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
myBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
并检索(我不知道我做错了)
@Override
protected void onResume()
{
super.onResume();
try {
File f = new File("imageDir/" + …Run Code Online (Sandbox Code Playgroud) 我有使用AsyncTask类的代码,用于使用数据库中的多个联系人填充listView.
@Override
protected void onResume()
{
super.onResume();
new MyTask().execute((Object[]) null);
} // end method onResume
Run Code Online (Sandbox Code Playgroud)
1.-为什么我通过这个:(Object[]) null)作为一个论点?
请参阅AsyncTask代码:
private class MyTask extends AsyncTask<Object, Object, Cursor>
{
//used for database conection purpose
ConectToDatabase databaseConnector =
new ConectToDatabase(ThisClass.this);
@Override
protected Cursor doInBackground(Object... params)
{
databaseConnector.open();
return databaseConnector.getMyContacts();
}
// use the Cursor returned from the doInBackground method
@Override
protected void onPostExecute(Cursor result)
{
//My cursorAdadper defined in early code
contactAdapter.changeCursor(result);
databaseConnector.close();
}
}
Run Code Online (Sandbox Code Playgroud)
另一个AsyncTask问题:
delete.execute(new Long[] { rowID });
Run Code Online (Sandbox Code Playgroud)
2.-为什么我传递这个: …
像这个问题
如何保存变量?
但是使用这个json代码:
{
"restarutant": [
{
"name": "Hotel Raja",
"photo": "http:\/\/i.imgur.com\/Mzt4u.jpg",
"address": "93, 2ndc ross, GDP etx.",
"area": "Vylaikaval",
"city": "Bangalore",
"rating": "4",
"cuisines": {
"first": "Chinese",
"second": "Korean"
}
},
{
"name": "Hotel Raja2",
"photo": "http:\/\/i.imgur2.com\/Mzt4u.jpg",
"address": "93, 2ndc ross, GDP etx. number2",
"area": "Vylaikaval2",
"city": "Bangalore2",
"rating": "4",
"cuisines": {
"first": "Chinese2",
"second": "Korean2"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
码:
JSONObject json = new JSONObject(thepreviousjson);
JSONArray jArray = json.getJSONArray("restaurant");
String name[] = new String[jArray.length()];
String photo[] = …Run Code Online (Sandbox Code Playgroud) 我有一个活动,用户按下按钮然后发送到片段,但我希望传递一个额外的片段使用:
活动A(按钮在哪里):
public OnClickListener publish = new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),ActivityB.class);
intent.putExtra("friendIdRowID", rowID);
startActivity(intent);
}
};
Run Code Online (Sandbox Code Playgroud)
活动B正在加载片段(我希望在其中检索额外的"friendIdRowID"),片段:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main2, container, false);
Bundle extras = getActivity().getIntent().getExtras();
if (extras != null)
{
String myString = extras.getString("friendIdRowID");
}
}
Run Code Online (Sandbox Code Playgroud)
但它无法正常工作,我可以做些什么来传递和检索额外的?谢谢.
我的意思是:
<?php echo "hello"; ?>
Run Code Online (Sandbox Code Playgroud)
反对:
<? echo "hello"; ?>
Run Code Online (Sandbox Code Playgroud)
(没有php).
它工作正常,但有任何后果/糟糕的编程实践?没有问题??一切都顺利吗?怎么会发生什么?
我在dart中创建了一个新项目,并添加了一些代码,但是当我运行时(如果我使用"Run in Dartium"或者Ctrl + R运行dart文件并不重要)dart文件没有显示按钮我在main中创建,也在main()方法中创建了我添加了print()以便在控制台中打印消息,但没有显示任何内容.
另外:如果我使用"Run as JavaScript"运行按钮正常显示,这就是我正在做的事情:

1.-我的HTML代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Capitulo9</title>
<link rel="stylesheet" href="capitulo9.css">
</head>
<body>
<script type="application/dart" src="capitulo9.dart"></script>
<script src="packages/browser/dart.js"></script>
capitulo9.dart
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
2.-我的dart文件(忘记上面的所有代码都被注释)我想打印消息并创建按钮:
main() {
print("I wish to print this in the console");
var startButton = new Element.html("<button>Start</button>");
document.body.children.add(startButton);
}
Run Code Online (Sandbox Code Playgroud)
3.-我用"Run in Dartium"运行它,并带有绿色图标4.-
这就是我得到的,没有按钮5.-
没有打印信息6.-
也没有打印信息
我怎么能想用飞镖跑?谢谢
我有这个代码:
try {
URL url = new URL (strURL);
input = url.openStream();
byte[] buffer = new byte[1500];
OutputStream output = new FileOutputStream ("/sdcard/"+pos+".png");
Run Code Online (Sandbox Code Playgroud)
我得到这个错误:不要硬编码/ SD卡/使用environment.getexternalstoragedirectory().getpath()而不是
OutputStream output = new FileOutputStream ("/sdcard/"+pos+".png");
Run Code Online (Sandbox Code Playgroud)
我已经读过:Android 4.2 - Environment.getExternalStorageDirectory().getPath()行为
所以问题是当我更换它时最终代码是什么?