芯片组的 GetText()(条目)
GetText() for a chipgroup (entry)
我是 java/android 的新手,我需要一个项目来实现芯片(条目)。我按照教程进行操作,芯片可以正常工作。 what i made
XML
<Button
android:id="@+id/email_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="buttonClick"
android:text="Ajouter"
android:textSize="10sp"
app:layout_constraintBottom_toTopOf="@+id/chip_group"
app:layout_constraintLeft_toRightOf="@+id/fields_2_form"
app:layout_constraintTop_toBottomOf="@+id/title_field_3">
</Button>
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/fields_2_form">
</com.google.android.material.chip.ChipGroup>
Activity
public void buttonClick(View view) {
final EditText fieldForm2 = findViewById(R.id.fields_2_form);
final ChipGroup chipGroup = findViewById(R.id.chip_group);
final Button emailButton = findViewById(R.id.email_button);
final Chip chip = new Chip(this);
ChipDrawable drawable = ChipDrawable
.createFromAttributes(this, null, 0, R.style.Widget_MaterialComponents_Chip_Entry);
chip.setChipDrawable(drawable);
chip.setCheckable(false);
chip.setClickable(false);
chip.setChipIconResource(R.drawable.ic_fingerprint_black_24dp);
chip.setIconStartPadding(3f);
chip.setPadding(60, 10, 60, 10);
chip.setText(fieldForm2.getText().toString());
// remove chip on click on the -
chip.setOnCloseIconClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
chipGroup.removeView(chip);
}
});
if (!EmailValid(fieldForm2.getText().toString())) {
Toast.makeText(getApplicationContext(),
"Veuillez rentrer un email valide",
Toast.LENGTH_LONG).show();
fieldForm2.setText("");
} else {
chipGroup.addView(chip);
fieldForm2.setText("");
}
}
好吧,但我的问题是当我需要从芯片获取所有键入的电子邮件用于另一个 activity。
我尝试用这种方法做到这一点:
public Intent getFormInfos() {
TextView mEditTextHour = findViewById(R.id.fields_1_form);
final Spinner spin = (Spinner) findViewById(R.id.Spinner);
final ChipGroup chipGroup = findViewById(R.id.chip_group);
//FIXME
String chiptext = chipGroup.INEEDTOGETCHIPTEXTHERE();
String myEditedText1 = mEditTextHour.getText().toString();
String spinnerText = spin.getSelectedItem().toString();
Intent intent = new Intent(this, ActivityListMareu.class);
ApiService.getmReunions().add(new Reunion(myEditedText1, spinnerText, chiptext));
return intent;
}
我需要做类似 chipgroup.getText() 的事情,但它不起作用我尝试了一些东西,但我真的对芯片感到困惑,实际上我不知道如何制作它。
有人对此有想法吗?
(抱歉我的英语不好)
使用这个你可以在 ChipGroup
.
中获取所有 Chip
的所有文本集
ArrayList<String> emails = new ArrayList<>();
for (int i = 0; i < chipGroup.getChildCount(); i++) {
String email = ((Chip) chipGroup.getChildAt(i)).getText().toString();
emails.add(email);
}
在你的情况下,如果你在 chipGroup
中只有一个 chip
,你可以直接:
if (chipGroup.getChildCount() > 0) {
CharSequence yourText = ((Chip) chipGroup.getChildAt(0)).getText();
}
这是在 Kotlin 中,但您基本上可以像任何 collection/sequence:
一样对 getChildren()
进行转换
val emails = chipGroup.children.map {
(it as Chip).text.toString()
}.toList()
我是 java/android 的新手,我需要一个项目来实现芯片(条目)。我按照教程进行操作,芯片可以正常工作。 what i made
XML
<Button
android:id="@+id/email_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="buttonClick"
android:text="Ajouter"
android:textSize="10sp"
app:layout_constraintBottom_toTopOf="@+id/chip_group"
app:layout_constraintLeft_toRightOf="@+id/fields_2_form"
app:layout_constraintTop_toBottomOf="@+id/title_field_3">
</Button>
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/fields_2_form">
</com.google.android.material.chip.ChipGroup>
Activity
public void buttonClick(View view) {
final EditText fieldForm2 = findViewById(R.id.fields_2_form);
final ChipGroup chipGroup = findViewById(R.id.chip_group);
final Button emailButton = findViewById(R.id.email_button);
final Chip chip = new Chip(this);
ChipDrawable drawable = ChipDrawable
.createFromAttributes(this, null, 0, R.style.Widget_MaterialComponents_Chip_Entry);
chip.setChipDrawable(drawable);
chip.setCheckable(false);
chip.setClickable(false);
chip.setChipIconResource(R.drawable.ic_fingerprint_black_24dp);
chip.setIconStartPadding(3f);
chip.setPadding(60, 10, 60, 10);
chip.setText(fieldForm2.getText().toString());
// remove chip on click on the -
chip.setOnCloseIconClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
chipGroup.removeView(chip);
}
});
if (!EmailValid(fieldForm2.getText().toString())) {
Toast.makeText(getApplicationContext(),
"Veuillez rentrer un email valide",
Toast.LENGTH_LONG).show();
fieldForm2.setText("");
} else {
chipGroup.addView(chip);
fieldForm2.setText("");
}
}
好吧,但我的问题是当我需要从芯片获取所有键入的电子邮件用于另一个 activity。 我尝试用这种方法做到这一点:
public Intent getFormInfos() {
TextView mEditTextHour = findViewById(R.id.fields_1_form);
final Spinner spin = (Spinner) findViewById(R.id.Spinner);
final ChipGroup chipGroup = findViewById(R.id.chip_group);
//FIXME
String chiptext = chipGroup.INEEDTOGETCHIPTEXTHERE();
String myEditedText1 = mEditTextHour.getText().toString();
String spinnerText = spin.getSelectedItem().toString();
Intent intent = new Intent(this, ActivityListMareu.class);
ApiService.getmReunions().add(new Reunion(myEditedText1, spinnerText, chiptext));
return intent;
}
我需要做类似 chipgroup.getText() 的事情,但它不起作用我尝试了一些东西,但我真的对芯片感到困惑,实际上我不知道如何制作它。
有人对此有想法吗?
(抱歉我的英语不好)
使用这个你可以在 ChipGroup
.
Chip
的所有文本集
ArrayList<String> emails = new ArrayList<>();
for (int i = 0; i < chipGroup.getChildCount(); i++) {
String email = ((Chip) chipGroup.getChildAt(i)).getText().toString();
emails.add(email);
}
在你的情况下,如果你在 chipGroup
中只有一个 chip
,你可以直接:
if (chipGroup.getChildCount() > 0) {
CharSequence yourText = ((Chip) chipGroup.getChildAt(0)).getText();
}
这是在 Kotlin 中,但您基本上可以像任何 collection/sequence:
一样对getChildren()
进行转换
val emails = chipGroup.children.map {
(it as Chip).text.toString()
}.toList()