dropdown revised

This commit is contained in:
2021-03-16 22:02:11 +01:00
parent 4404093c83
commit b6823dbc42
5 changed files with 102 additions and 29 deletions
@@ -0,0 +1,73 @@
package de.joel.zoomhelper;
import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class AutoSuggestAdapter extends ArrayAdapter<String> implements Filterable {
private List<String> mlistData;
public AutoSuggestAdapter(@NonNull Context context, int resource) {
super(context, resource);
mlistData = new ArrayList<>();
}
public void setData(List<String> list) {
mlistData.clear();
mlistData.addAll(list);
}
@Override
public int getCount() {
return mlistData.size();
}
@Nullable
@Override
public String getItem(int position) {
return mlistData.get(position);
}
/**
* Used to Return the full object directly from adapter.
*
* @param position
* @return
*/
public String getObject(int position) {
return mlistData.get(position);
}
@NonNull
@Override
public Filter getFilter() {
Filter dataFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (constraint != null) {
filterResults.values = mlistData;
filterResults.count = mlistData.size();
}
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if (results != null && (results.count > 0)) {
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
};
return dataFilter;
}
}
@@ -27,6 +27,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
@@ -44,7 +45,7 @@ class InstantAutoComplete extends com.google.android.material.textfield.Material
}
@Override
public boolean enoughToFilter() {
return true;
return false;
}
}
@@ -146,9 +147,7 @@ public class MainActivity extends AppCompatActivity {
}
});
builder.setNegativeButton(R.string.no, (dialog, which) -> {
dialog.dismiss();
});
builder.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss());
AlertDialog alert = builder.create();
alert.show();
@@ -205,24 +204,22 @@ public class MainActivity extends AppCompatActivity {
}
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
ImageView dropdown = findViewById(R.id.iconDropdownMeetingName);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, meetingNames);
//ImageView dropdown = findViewById(R.id.iconDropdownMeetingName);
AutoSuggestAdapter adapter = new AutoSuggestAdapter(this, android.R.layout.simple_dropdown_item_1line);
adapter.setData(Arrays.asList(meetingNames));
textMeetingName.setAdapter(adapter);
textMeetingName.setOnTouchListener((View.OnTouchListener) (paramView, paramMotionEvent) -> {
adapter.getFilter().filter(null);
textMeetingName.showDropDown();
return false;
});
textMeetingName.setOnTouchListener((View.OnTouchListener) (paramView, paramMotionEvent) -> false);
textMeetingName.setOnItemClickListener((arg0, view, arg2, arg3) -> fillWithSelectedMeeting());
dropdown.setOnClickListener(v -> {
/*dropdown.setOnClickListener(v -> {
textMeetingName.showDropDown();
adapter.getFilter().filter(null);
});
});*/
}
@SuppressLint("ClickableViewAccessibility")
public void fillDropdownAttendeeName(int meetingIndex) {
Meeting meeting = getMeetings().get(meetingIndex);
ArrayList<Attendee> attendees = meeting.attendees;
@@ -233,16 +230,19 @@ public class MainActivity extends AppCompatActivity {
}
AutoCompleteTextView textName = findViewById(R.id.textBoxName);
ImageView dropdown = findViewById(R.id.iconDropdownAttName);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, attNames);
//ImageView dropdown = findViewById(R.id.iconDropdownAttName);
AutoSuggestAdapter adapter = new AutoSuggestAdapter(this, android.R.layout.simple_dropdown_item_1line);
adapter.setData(Arrays.asList(attNames));
textName.setAdapter(adapter);
textName.setOnTouchListener((View.OnTouchListener) (paramView, paramMotionEvent) -> false);
textName.setOnItemClickListener((arg0, view, arg2, arg3) -> fillWithSelectedAtt());
dropdown.setOnClickListener(v -> {
/*dropdown.setOnClickListener(v -> {
textName.showDropDown();
adapter.getFilter().filter(null);
});
});*/
}
private void fillWithSelectedAtt() {