我在互联网上搜索了很多,但找不到确切的解决方案。这是我上次从 SO 尝试的链接。 从 ChipGroup 中获取选定的 Chips
我想在单击按钮时从芯片组中获取选定的芯片。
此函数包含在 RecyclerView 中显示名称的信息
private void getNames() {
List<String> names = Arrays.asList(getResources().getStringArray(R.array.names));
int count = 0;
for ( String name : names){
list.add(new Names(name));
count++;
}
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
namesAdapter = new NamesAdapter(MainActivity.this, list);
recyclerView.setAdapter(namesAdapter);
}
Run Code Online (Sandbox Code Playgroud)
当单击 RecyclerView 项时,将一个芯片添加到 ChipGroup 中,这是功能
public void onItemSelected(Names name) {
Chip chip = new Chip(this);
chip.setText(name.getName());
chip.setCloseIconVisible(true);
chip.setCheckable(false);
chip.setClickable(false);
chip.setOnCloseIconClickListener(this);
chipGroup.addView(chip);
chipGroup.setVisibility(View.VISIBLE);
}
Run Code Online (Sandbox Code Playgroud)
从 ChipGroup 获取值的函数
public void getChipGroupValues(){
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View …Run Code Online (Sandbox Code Playgroud) java android android-chips material-components material-components-android