-1
I’m having trouble showing the dropdown of the items, it is appearing below the keyboard, as in the image attached.
Would you have a way to make the dropdown show up the textview?
Edited, code added
XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:background="#ffffff"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textSize="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_dateText"
android:textStyle="bold|italic"
android:text="Data" />
<TextView
android:textSize="@dimen/listview_size_font_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_date"
android:text=""
android:layout_gravity="right" />
<TextView
android:textSize="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_saleText"
android:textStyle="bold|italic"
android:text="Pedido" />
<TextView
android:textSize="@dimen/listview_size_font_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_saleNumber"
android:text=""
android:layout_gravity="right" />
<TextView
android:textSize="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_clientText"
android:textStyle="bold|italic"
android:text="Cliente" />
<AutoCompleteTextView
android:hint="Busque pelo cliente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:windowSoftInputMode="stateHidden|adjustPan"
android:dropDownHeight="500dp"
android:id="@+id/ac_client" />
<TextView
android:textSize="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_fpaymentText"
android:textStyle="bold|italic"
android:text="Forma de pagamento" />
<AutoCompleteTextView
android:hint="Busque pela forma"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:windowSoftInputMode="stateHidden|adjustPan"
android:dropDownHeight="100dp"
android:id="@+id/ac_fpayment" />
<TextView
android:textSize="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_paymentText"
android:textStyle="bold|italic"
android:text="Condição de pagamento" />
<AutoCompleteTextView
android:hint="Busque pela condição"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:windowSoftInputMode="stateHidden|adjustPan"
android:dropDownHeight="100dp"
android:id="@+id/ac_payment" />
<TextView
android:textSize="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_obsText"
android:textStyle="bold|italic"
android:text="Forma de pagamento" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Observação"
android:id="@+id/tv_obs" />
</LinearLayout>
</ScrollView>
Autocompleteadapter
public class AutoCompleteAdapter extends ArrayAdapter<ACObject> {
Context context;
int resource, textViewResourceId;
List<ACObject> items, tempItems, suggestions;
public AutoCompleteAdapter(Context context, int resource, int textViewResourceId, List<ACObject> items) {
super(context, resource, textViewResourceId, items);
Log.e("Adapter", "items -> "+items);
this.context = context;
this.resource = resource;
this.textViewResourceId = textViewResourceId;
this.items = items;
tempItems = new ArrayList<ACObject>(items); // this makes the difference.
suggestions = new ArrayList<ACObject>();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(resource, parent, false);
}
ACObject object = items.get(position);
if (object != null) {
TextView lblName = (TextView) view.findViewById(textViewResourceId);
if (lblName != null)
lblName.setText(object.getName());
}
return view;
}
@Override
public Filter getFilter() {
return nameFilter;
}
Filter nameFilter = new Filter() {
@Override
public CharSequence convertResultToString(Object resultValue) {
String str = ((ACObject) resultValue).getName();
return str;
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
if (constraint != null) {
suggestions.clear();
for (ACObject object : tempItems) {
if (object.getName().toLowerCase().contains(constraint.toString().toLowerCase())) {
suggestions.add(object);
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = suggestions;
filterResults.count = suggestions.size();
return filterResults;
} else {
return new FilterResults();
}
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
List<ACObject> filterList = (ArrayList<ACObject>) results.values;
if (results != null && results.count > 0) {
clear();
for (ACObject object : filterList) {
add(object);
notifyDataSetChanged();
}
}
}
};
}
Acobject
public class ACObject {
public int id;
public String code;
public String name;
public ACObject(int id, String code, String name) {
this.id = id;
this.code = code;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Newsalestabinfo
public class NewSalesTabInfo extends Fragment {
private String saleNumber = "";
List<ACObject> mListClient;
List<ACObject> mListPayment;
AutoCompleteAdapter adapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
saleNumber = getArguments().getString("requestNumber");
View v = View.inflate(getContext(), R.layout.new_sales_tab_info, null);
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String date = df.format(c.getTime());
TextView tv_saleDate = (TextView)v.findViewById(R.id.tv_date);
TextView tv_saleNumber = (TextView)v.findViewById(R.id.tv_saleNumber);
AutoCompleteTextView ac_client = (AutoCompleteTextView)v.findViewById(R.id.ac_client);
AutoCompleteTextView ac_payment = (AutoCompleteTextView)v.findViewById(R.id.ac_payment);
tv_saleDate.setText(date);
tv_saleNumber.setText(saleNumber);
mListClient = retrieveClients();
ac_client.setThreshold(1);
adapter = new AutoCompleteAdapter(getContext(), R.layout.autocomplete_list, R.id.tv_name, mListClient);
ac_client.setAdapter(adapter);
mListPayment = retrievePayment();
ac_payment.setThreshold(1);
adapter = new AutoCompleteAdapter(getContext(), R.layout.autocomplete_list, R.id.tv_name, mListPayment);
ac_payment.setAdapter(adapter);
return v;
}
private List<ACObject> retrieveClients() {
List<ACObject> list = new ArrayList<ACObject>();
DBController dbCtrl = new DBController(getContext());
String[] fieldTable = {"id", "A1_COD", "A1_NOME"};
Cursor dbClients = dbCtrl.selectAllData("SA1", fieldTable);
while (dbClients.moveToNext()) {
list.add(new ACObject(dbClients.getInt(dbClients.getColumnIndex("id")), dbClients.getString(dbClients.getColumnIndex("A1_COD")), dbClients.getString(dbClients.getColumnIndex("A1_NOME"))));
}
return list;
}
private List<ACObject> retrievePayment() {
List<ACObject> list = new ArrayList<ACObject>();
DBController dbCtrl = new DBController(getContext());
String[] fieldTable = {"id", "E4_CODIGO", "E4_DESCRI"};
Cursor dbPayment = dbCtrl.selectAllData("SE4", fieldTable);
while (dbPayment.moveToNext()) {
list.add(new ACObject(dbPayment.getInt(dbPayment.getColumnIndex("id")), dbPayment.getString(dbPayment.getColumnIndex("E4_CODIGO")), dbPayment.getString(dbPayment.getColumnIndex("E4_DESCRI"))));
}
return list;
}
}