我想从意图中获取另一个活动中的字符串.这是创建我的意图的方法
val intent = Intent(this, Main2Activity::class.java)
intent.putExtra("samplename", "abd")
startActivity(intent)
Run Code Online (Sandbox Code Playgroud)
如何在另一个活动中获得此意图的价值
我有一个帐户列表,当我进行长按时,我想从arraylist中删除该项目.我正在尝试从alertdialog中删除它,但我得到了ConcurrentModificationException.这是崩溃的地方:
listAccounts.forEachIndexed { index, account ->
if (idParamether == account.id) {
listAccounts.remove(account)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Response 对象返回一些内容。这些是实现的接口:
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
Run Code Online (Sandbox Code Playgroud)
然后,在 GET 函数中,我创建自己的 JSON,并尝试将其作为响应返回:
$app->get('/getpersons', function(Request $request, Response $response, $args){
$person= new stdClass();
$person->id = 1;
$person->name='Name example';
$person->address = 'Street example';
return $response->getBody()->write(json_encode($person));
});
Run Code Online (Sandbox Code Playgroud)
但我收到下一个错误:
Return value of Slim\Handlers\Strategies\RequestResponse::__invoke() must
implement interface Psr\Http\Message\ResponseInterface
Run Code Online (Sandbox Code Playgroud)
我不知道发生了什么事。有什么帮助吗?
我在服务器上有一个php文件,我必须获取信息,但我不知道如何将参数传递给查询.
例如,如果我有这个查询:SELECT*FROM accounttable WHERE idaccount = 1,我想将此1作为参数传递,我该怎么办?
val stringRequest = StringRequest(Request.Method.POST, URL, Response.Listener<String>{ s ->
try {
val array = JSONArray(s)
for (i in 0..array.length() - 1) {
val objectAccount = array.getJSONObject(i)
val account = Account(
objectAccount.getString("accountplace"),
objectAccount.getString("useraccount"),
objectAccount.getString("accountpass"))
listAccounts.add(account)
}
}catch (e: JSONException){
e.printStackTrace()
}
}, Response.ErrorListener { error: VolleyError? -> Log.e("error", "error") })
val requesQueue = Volley.newRequestQueue(this)
requesQueue.add<String>(stringRequest)
Run Code Online (Sandbox Code Playgroud)