2
I’m starting my studies on Android now, and I’m doing some tests.
I have two Autocomplittextview fields, in both an id and a description is shown. X1 and X2 (fictitious names). The X2 list is filtered by the choice of X1. Has Some way that if the user deletes the id(even if it is only a number) of X1 the field X2 is cleared?
X1 = Ccusto X2 = Operation
My fields xml ta so.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="C.Custo"
android:id="@+id/textView14"
android:textSize="25sp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et_ccusto"
android:layout_weight="1"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/btn_ccusto"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Operacão"
android:id="@+id/textView15"
android:textSize="25sp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et_operacao"
android:layout_weight="1"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/btn_operacao"
android:textSize="20sp" />
I’m using this in my Activity.
acetCcusto.setAdapter(adapterCcusto);
acetOperacao.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(!acetCcusto.getText().toString().equals("")){
int cdEquipamento = util.getInt(tvEquip.getText().toString());
int cdCcusto = util.getInt(acetCcusto.getText().toString());
adapterOperacao = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, CcBO.getArrayOperacao(cdCcusto));
adapterOperacao = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, EOBO.getArrayCdOperacao(cdEquipamento));
acetOperacao.setAdapter(adapterOperacao);
}
}
});
btnCcusto.setOnClickListener(new View.Onclicklistener() {
@Override
public void onClick(View v) {
Log.i(TAG, "onClick: ");
new MaterialDialog.Builder(context)
.title(R.string.title)
.items(CcBO.getArrayCcusto())
.itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
acetCcusto.setText(text.toString());
acetOperacao.setText("");
}
})
.show();
}
});
btnOperacao.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!acetCcusto.getText().toString().equals("")) {
int cdCcusto = util.getInt(acetCcusto.getText().toString());
cdOperacao = CcBO.getArrayOperacao(cdCcusto);
if (cdOperacao!=null){
adapterOperacao = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, cdOperacao);
}
new MaterialDialog.Builder(context)
.title(R.string.title)
.items(CcBO.getArrayOperacao(cdCcusto))
.itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
acetOperacao.setText(text.toString());
}
})
.show();
}
}
});
That’s right. Thank you
– Edumachdo