我想在我的BaseAdapter上有一个搜索功能。 以下是我的BaseAdapter中的代码:
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by Fabi on 12.09.2015.
*/
public class GetAllMessagesListViewAdapter extends BaseAdapter implements Filterable {
private JSONArray dataArray;
private Activity activity;
private static LayoutInflater layoutInflater = null;
public GetAllMessagesListViewAdapter(JSONArray jsonArray, Activity activity) {
this.dataArray = jsonArray;
this.activity = activity;
layoutInflater = (LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return dataArray.length();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ListCell cell;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.get_all_customer_list_view, null);
cell = new ListCell();
cell.customer = (TextView) convertView.findViewById(R.id.customer);
convertView.setTag(cell);
} else {
cell = (ListCell) convertView.getTag();
}
try {
JSONObject jsonObject = dataArray.getJSONObject(position);
cell.customer.setText(jsonObject.getString("name"));
} catch (JSONException e) {
e.printStackTrace();
}
return convertView;
}
@Override
public Filter getFilter() {
Filter filter = null;
return filter;
}
private class ListCell {
private TextView sender, receiver, message, customer;
}
//SEARCH FUNCTION
}
现在我想从jsonArray中搜索客户的显示名称。任何建议和解决方案?非常感谢您的帮助!