我有一个Android应用程序,我想读取和写入ArrayList<MyClass>
内部存储.
写作部分工作(我相信,尚未测试它:-)):
ArrayList<MyClass> aList;
public void saveToInternalStorage() {
try {
FileOutputStream fos = ctx.openFileOutput(STORAGE_FILENAME, Context.MODE_PRIVATE);
fos.write(aList.toString().getBytes());
fos.close();
}
catch (Exception e) {
Log.e("InternalStorage", e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
但我现在要做的是从存储中读取整个ArrayList并将其作为ArrayList返回,如下所示:
public ArrayList<MyClass> readFromInternalStorage() {
ArrayList<MyClass> toReturn;
FileInputStream fis;
try {
fis = ctx.openFileInput(STORAGE_FILENAME);
//read in the ArrayList
toReturn = whatever is read in...
fis.close();
} catch (FileNotFoundException e) {
Log.e("InternalStorage", e.getMessage());
} catch (IOException e) {
Log.e("InternalStorage", e.getMessage());
}
return toReturn
}
Run Code Online (Sandbox Code Playgroud)
我以前从未在Android文件中读过,所以我不知道这是否可能.但是我有一种方式可以阅读我的习惯ArrayList
吗?
我有jQuery mobile的问题:
我有一个登录按钮,点击时会弹出登录表单,但是当页面加载时,弹出div不会被隐藏...
我尝试了大约一百种不同的方法让它隐藏(通过添加一些jQuery移动属性),但没有任何方法可行.
代码:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<a href="#popupLogin" data-rel="popup" data-role="button" data-transition="pop" data-inline="true">Sign in</a>
<div data-role="popup" id="popupLogin" data-theme="a" data-overlay-theme="b" >
<h3>Please sign in</h3>
<label for="un">Username:</label>
<input id="un" type="text" data-theme="a" placeholder="username" value="" name="user" />
<label for="pw">Password:</label>
<input id="pw" type="password" data-theme="a" placeholder="password" value="" name="pw">
<div data-theme="b" aria-disabled="false">
</div>
Run Code Online (Sandbox Code Playgroud)
有人知道我做错了什么吗?谢谢
我正在编写一个带有自定义适配器的Android应用程序,用于列表视图.
适配器是mainActivity类中的变量,包含自定义类的列表.我需要从其他活动访问此列表中的类,但是当应用程序到达适配器中的getItem(position)时,应用程序似乎崩溃.
基本上这就是应用程序的样子:
在MainActivity类中有一个基本的自定义适配器:
public class MainActivity extends Activity {
public static MyAdapter myAdapter;
...
}
Run Code Online (Sandbox Code Playgroud)
适配器仅具有getItem等基本功能,并具有自定义(基本)类的列表
public class MyAdapter extends BaseAdapter {
private ArrayList<MyClass> tours = new ArrayList<MyClass>();
@Override
public Object getItem(int arg0) {
return getItem(arg0);
}
...
}
Run Code Online (Sandbox Code Playgroud)
打开其他活动时,会向其传递索引以从列表中访问某个对象.
唯一的问题是当我尝试从这个列表中访问一个类时,应用程序崩溃了......我使用以下代码从适配器的列表中访问该类:
MyClass myClass = (MyClass)MainActivity.myAdapter.getItem(index);
Run Code Online (Sandbox Code Playgroud)
有人能告诉我我做错了什么或为什么应用程序崩溃?
我有一个自定义ListAdapter,它在AsyncTask中从Internet获取数据.
数据完全添加到列表中,但是当我尝试执行操作时,应用程序崩溃了......
我确定这是因为我正在调用notifyDataSetChanged(); 在错误的时间(即在AsyncTask结束之前).
我现在得到了什么:
public class MyListAdapter extends BaseAdapter {
private ArrayList<String> mStrings = new ArrayList<String>();
public MyListAdapter() {
new RetreiveStringsTask().execute(internet_url);
//here I call the notify function ****************
this.notifyDataSetChanged();
}
class RetreiveStringsTask extends AsyncTask<String, Void, ArrayList<String>> {
private Exception exception;
@Override
protected ArrayList<String> doInBackground(String... urls) {
try {
URL url= new URL(urls[0]);
//return arraylist
return getStringsFromInternet(url);;
} catch (Exception e) {
this.exception = e;
Log.e("AsyncTask", exception.toString());
return null;
}
}
@Override
protected void onPostExecute(ArrayList<String> stringsArray) {
//add the tours …
Run Code Online (Sandbox Code Playgroud) 我正在尝试通过Laravel的迁移文件生成我的数据库,但是当我尝试这样做时,我收到以下错误:
PHP Parse error: syntax error, unexpected '[', expecting ')' in D:\wamp24\www\laravel\app\controllers\SomeController.php
Run Code Online (Sandbox Code Playgroud)
这让我发疯,我可以在我的控制器中注释掉代码时运行迁移文件,但我不能继续这样做.
我也不想重写我的所有代码,因为我几乎每次声明一个数组时都使用方括号(使用方括号比输入'array(〜)'快很多...)
我在wampserver(2.4)上使用PHP 5.3.13,在Win 8.1上使用apache 2.2.22.
Laravel Framework版本4.0.10.
给出错误的代码如下:
class SomeController extends BaseController {
public function someFunc() {
$var= Model::create([
'title' => Input::get('title'),
'description' => Input::get('description'),
]);
}
}
Run Code Online (Sandbox Code Playgroud)
谁知道这个错误的解决方案?