我正在尝试动态设置复选框状态检查为false / true。 到目前为止我所拥有的是:
setConverter(new StringConverter<CellDataHolder>() {
@Override
public String toString(CellDataHolder arg0) {
if(isEditing()){ //whether it is an edit
arg0.badMatch =
arg0.value.matches(".*[a-zA-Z]+.*");//here you add your algorithm
}
return arg0.value;
}
@Override
public CellDataHolder fromString(String arg0) {
getItem().value = arg0;
return getItem();
}
});
当我从控制台获取日志时,会检查一些复选框:true和一些选中:false。问题是在视觉上我看到所有复选框都已选中。我们正在使用材料设计,这里是复选框创建的一些示例:
package com.codecanyon.xxxx;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.randombot.swaptheglyph.SwapTheGlyph;
import com.randombot.swaptheglyph.utils.Resolver;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class AndroidLauncher extends AndroidApplication implements Resolver {
private static final boolean ADS = true;
private AdView adView;
private String facebook;
private String twitter;
private String market;
private String randombot;
private String appName;
private String googlePlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.facebook = getString(R.string.facebook);
this.twitter = getString(R.string.twitter);
this.market = getString(R.string.market);
this.randombot = getString(R.string.randombot);
this.appName = getString(R.string.app_name);
this.googlePlay = getString(R.string.google_play);
// Create the libgdx View
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.hideStatusBar = true;
cfg.useAccelerometer = false;
cfg.useCompass = false;
cfg.useImmersiveMode = true;
cfg.useWakelock = false;
if (ADS) {
// Create the layout
RelativeLayout layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow()
.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
View gameView = initializeForView(new SwapTheGlyph(this), cfg);
this.adView = new AdView(this);
this.adView.setAdUnitId(getString(R.string.banner_id));
this.adView.setAdSize(AdSize.SMART_BANNER);
this.adView.loadAd(new AdRequest.Builder().build());
/**
* Invoking { requestWindowFeature(Window.FEATURE_NO_TITLE); } will
* make the add view not to be shown until the next event (updating
* the ad every 60 seconds or pause/resume) By calling
* setBackgroundColor we force the add to show itself as soon as
* it's loaded.
*/
this.adView.setBackgroundColor(Color.TRANSPARENT);
// Add the libgdx view
layout.addView(gameView);
// Add the AdMob view
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(this.adView, adParams);
// Hook it all up
setContentView(layout);
} else {
initialize(new SwapTheGlyph(this), cfg);
}
}
@Override
protected void onPause() {
if (ADS) {
adView.pause();
}
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
if (ADS) {
adView.resume();
}
}
@Override
protected void onDestroy() {
if (ADS) {
adView.destroy();
}
super.onDestroy();
}
@Override
public void onBackPressed() {
}
@Override
public void resolve(int which, int arg) {
switch (which) {
case RANKING: {
break;
}
case SHARE: {
Intent sharingIntent = new Intent(
android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Let's play " + this.appName + "!\n"
+ this.googlePlay;
sharingIntent
.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
break;
}
case SHOW_URI: {
String res = "";
switch (arg) {
case SHOW_URI_FACEBOOK:
res = this.facebook;
break;
case SHOW_URI_TWITTER:
res = this.twitter;
break;
case SHOW_URI_MARKET:
res = this.market;
break;
case SHOW_URI_RANDOMBOT:
res = this.randombot;
break;
}
Uri myUri = Uri.parse(res);
Intent intent = new Intent(Intent.ACTION_VIEW, myUri);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);
break;
}
default:
break;
}
}
}
然后我这样做:
for(var i = 0; i < bookmakers.length; i++) {
$('#' + bookmakers[i].id + '-checkbox').prop('checked', filters['bookmakers'][bookmakers[i].id]).change();
console.log($('#' + bookmakers[i].id + '-checkbox'));
}
更新视图。任何想法?
答案 0 :(得分:0)
有些浏览器不允许id以数字开头。特别是CSS不允许以数字开头的选择器。尝试将#1复选框更改为#checkbox-1
答案 1 :(得分:0)
也许您应该编写一个JSfiddle,以便我们可以查看和测试您的代码。在此期间,您是否尝试过使用Javascript设置复选框状态?
document.getElementById('yourElemID').checked = true; // or false
答案 2 :(得分:0)
有多种方法可以解决这个问题。我用过的就是:
for(var i = 0; i < bookmakers.length; i++) {
setCheckboxValue($('#' + bookmakers[i].id + '-checkbox'), filters['bookmakers'][bookmakers[i].id]);
}
然后setCheckboxValue
函数看起来像这样:
function setCheckboxValue($el, value) {
var $parent = $el.prop('checked', value).parent();
removeOrAddClass($parent, 'is-checked', value);
}
这不是解决此问题的最简洁方法。您可以在MaterialCheckbox
DOM元素中找到$el.get(0)
对象,并使用check
和uncheck
方法。