Java 带有自定义适配器的Android自定义AutoCompleteTextView
基本上,我希望在edittext中编写一些东西,然后将调用一个web http请求,该请求返回一个JSONObject,该JSONObject包含一个JSON数组,该数组包含其中的某个值。我需要用JSON对象的结果填充autocompletetextview附带的下拉列表 我可以做第二点,也就是说,我可以使用扩展arrayadapter的自定义适配器类来填充下拉列表中所需的值,如下所示。我的问题是第一位,如何覆盖AutoCompleteTextView,使其不显示从数组中筛选出的常量值,而是显示给它的值?我根本不希望它是可过滤的。以下是autocompletetextview的源代码Java 带有自定义适配器的Android自定义AutoCompleteTextView,java,android,autocomplete,android-arrayadapter,autocompletetextview,Java,Android,Autocomplete,Android Arrayadapter,Autocompletetextview,基本上,我希望在edittext中编写一些东西,然后将调用一个web http请求,该请求返回一个JSONObject,该JSONObject包含一个JSON数组,该数组包含其中的某个值。我需要用JSON对象的结果填充autocompletetextview附带的下拉列表 我可以做第二点,也就是说,我可以使用扩展arrayadapter的自定义适配器类来填充下拉列表中所需的值,如下所示。我的问题是第一位,如何覆盖AutoCompleteTextView,使其不显示从数组中筛选出的常量值,而是显示
在返回自定义内部筛选器的PersonalAdapter override getFilter()方法中,您必须实现它的两个方法:PerformFilter()和publishResults(),PerformFilter在工作线程中运行,在这里您调用web请求,在publishResults中,只需调用clear()和add()项谢谢。虽然,我也从这个问题中得到了帮助
public class PersonAdapter extends ArrayAdapter
{
// we use the constructor allowing to provide a List of objects for the data
// to be binded.
public PersonAdapter(Context context, int textViewResourceId,
List objects) {
super(context, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// retrieve the Person object binded at this position
final Person p = getItem(position);
// A ViewHolder keeps references to children views to avoid unneccessary
// calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is no
// need
// to reinflate it. We only inflate a new View when the convertView
// supplied
// by ListView is null.
if (convertView == null) {
convertView = View.inflate(getContext(), R.layout.list_item, parent, false);
// Creates a ViewHolder and store references to the two children
// views
// we want to bind data to.
holder = new ViewHolder();
holder.textName = (TextView) convertView
.findViewById(R.id.textName);
holder.textEmail = (TextView) convertView
.findViewById(R.id.textEmail);
holder.picture = (ImageView) convertView.findViewById(R.id.image);
holder.picture.setFocusable(false);
holder.picture.setFocusableInTouchMode(false);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
holder.textName.setText(p.getName());
holder.textEmail.setText(p.getEmail());
holder.picture.setImageResource(p.getResImage());
//click on the picture
holder.picture.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getContext(),
"Clicked on " + p.getName() + "'s picture",
Toast.LENGTH_SHORT).show();
}
});
return convertView;
}
/**
*
* Inner holder class for a single row view in the ListView
*
*/
static class ViewHolder {
TextView textName, textEmail;
ImageView picture;
}
}