【发布时间】:2021-07-03 02:32:36
【问题描述】:
当用户选择并提交到firebase时如何获取chipgroup值?
我已经编写了代码,但是当用户选择并将日期提交到 firebase 时,我只得到了值 -1。我不知道发生了什么。
String[] CampSite = new String[]{getApplicationContext().getResources().getString(R.string.campsite_wifi),
getApplicationContext().getResources().getString(R.string.campsite_wheelchair),
getApplicationContext().getResources().getString(R.string.campsite_water_from_tap),
getApplicationContext().getResources().getString(R.string.campsite_toilet),
getApplicationContext().getResources().getString(R.string.campsite_swimming_pool),
getApplicationContext().getResources().getString(R.string.campsite_surface),
getApplicationContext().getResources().getString(R.string.campsite_suit_any_car),
getApplicationContext().getResources().getString(R.string.campsite_pet_welcome),
getApplicationContext().getResources().getString(R.string.campsite_laundromat),
getApplicationContext().getResources().getString(R.string.campsite_large_vehicle_access),
getApplicationContext().getResources().getString(R.string.campsite_kitchen),
getApplicationContext().getResources().getString(R.string.campsite_internet),
getApplicationContext().getResources().getString(R.string.campsite_household_power),
getApplicationContext().getResources().getString(R.string.campsite_hot_shower),
getApplicationContext().getResources().getString(R.string.campsite_dump_station),
getApplicationContext().getResources().getString(R.string.campsite_credit_card),
getApplicationContext().getResources().getString(R.string.campsite_cellular_signal),
getApplicationContext().getResources().getString(R.string.campsite_caravan_power),
getApplicationContext().getResources().getString(R.string.campsite_cabin),
getApplicationContext().getResources().getString(R.string.campsite_bed_supplied),
getApplicationContext().getResources().getString(R.string.campsite_bbq),
};
chipGroup = findViewById(R.id.CampSite);
for (String camp : CampSite)
{
Chip chip = new Chip(this);
chip.setText(camp);
chip.setChipBackgroundColorResource(R.color.colorAccent);
chip.setCloseIconVisible(true);
chip.setTextColor(getResources().getColor(R.color.white));
//chip.setTextAppearance(R.style.ChipTextAppearance);
chip.setId(ViewCompat.generateViewId());
// edit:
chip.setCheckable(true);
chipGroup.addView(chip);
};
// OnclickChange item to check
chipGroup.setOnCheckedChangeListener(new ChipGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(ChipGroup group, int checkedId) {
group.isClickable();
}
});
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Campsite");
String postid = reference.push().getKey();
hashMap.put("CamperSiteSummary", chipGroup.getCheckedChipId());
我希望我能得到像 wifi、campsite_wheelchair、campsite_suit_any_car 等这样的价值
【问题讨论】:
标签: android android-chips