我有一个动态复选框列表视图。选择多个复选框时,我得到了正确的数组列表,但是当我一个接一个地选中两个复选框,然后取消选中一个复选框时,它应该选中一个复选框,但是选中了之前选中的两个复选框。
delete t
from your_table t
left join
(
select id
from your_table
order by value desc
limit 5
) tmp on t.id = tmp.id
where tmp.id is null
对于arraylist,我有一种方法@Configuration
public class HttpConfig {
@Bean
public UndertowServletWebServerFactory servletWebServerFactory(ApplicationProperties properties) {
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
factory.addBuilderCustomizers((UndertowBuilderCustomizer) builder ->
builder.setServerOption(UndertowOptions.ALLOW_UNESCAPED_CHARACTERS_IN_URL, Boolean.TRUE));
return factory;
}
}
,并且取消选中复选框后我没有得到正确的列表。
rd_student.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String value=objects.get(position).getUserName();
dbs=new DataBeanStudent();
//is chkIos checked?
if (((CheckBox) v).isChecked()) {
if (stringArray.contains(value)){
Toast.makeText(context, "Already added", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "Added", Toast.LENGTH_SHORT).show();
stringArray.add(value);
selectedStrings.add(value);
dbs.setUserName(value);
studentArray.add(dbs);
saveDataInSP(stringArray, finalV, studentArray);
}
}else
{
if (stringArray.contains(value)){
selectedStrings.remove(value);
stringArray.remove(value);
studentArray.remove(value);
Toast.makeText(context, "Removed", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "Already Removed", Toast.LENGTH_SHORT).show();
}
}
}
});
在getSelectedString()
中被称为 ArrayList<String> getSelectedString(){
return selectedStrings;
}
getSelectedString()
检查下图。
saveDataInSP(ArrayList<String> stringArray, View view, ArrayList<DataBeanStudent> studentArray)
答案 0 :(得分:0)
请勿将OnClickListener用于Checkbox,而应使用OnCheckedChangeListener。
$api_key="my-api-key";
$json='{
"longUrl": "honortraders-2.myshopify.com/admin"
}';
$url="https://www.googleapis.com/urlshortener/v1/url?&key=".$api_key;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($curl);
curl_close ($curl);
echo $response;*i am trying to use google urlshortner api but i am getting forbidden error*
此外,当我们使用ListView或RecyclerView时,子视图也将被回收。 因此,请始终在上面的代码之后将其包括在适配器中。 (假设上面的代码也在适配器中。)
rd_student.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String value=objects.get(position).getUserName();
dbs=new DataBeanStudent();
//is chkIos checked?
if (isChecked) {
if (stringArray.contains(value)){
Toast.makeText(context, "Already added", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "Added", Toast.LENGTH_SHORT).show();
stringArray.add(value);
selectedStrings.add(value);
dbs.setUserName(value);
studentArray.add(dbs);
saveDataInSP(stringArray, finalV, studentArray);
}
}else
{
if (stringArray.contains(value)){
selectedStrings.remove(value);
stringArray.remove(value);
studentArray.remove(value);
Toast.makeText(context, "Removed", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "Already Removed", Toast.LENGTH_SHORT).show();
}
}
}
});
希望这会有所帮助。