我正在调用以下方法在我的Android应用中填充recyclerview:
private void getDirectoriosFromDB(int id) {
AsyncTask<Integer, Void, Void> asyncTask = new AsyncTask<Integer, Void, Void>() {
@Override
protected Void doInBackground(Integer... addressesIds) {
// Log.d("HOLA PERFIL", "UID REGISTRADO ANTES DE CARGAR REECYCLER: " + user_id);
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://...directorio_todos.php")
.build();
try {
okhttp3.Response response = client.newCall(request).execute();
JSONArray array = new JSONArray(response.body().string());
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
Log.d("HOLA ADDRESSES", "DIRECCION LEIDA: " + i);
Directorio directorio = new Directorio(object.getInt("id_directorio"),
object.getString("nombre"),
object.getString("apellidos"),
object.getString("apodo"),
object.getString("cumple"),
object.getString("conyuge"),
object.getString("cumple_conyuge"),
object.getString("aniversario_bodas"),
object.getString("empresa"),
object.getString("direccion_empresa"),
object.getString("tel_negocio"),
object.getString("fecha_ingreso"),
object.getString("num_rotario"),
object.getString("padrino"),
object.getString("direccion_casa"),
object.getString("tel_casa"),
object.getString("celular"),
object.getString("email"),
object.getString("clasificacion"),
object.getString("imagen")
);
directorios.add(directorio);
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
adapter.notifyDataSetChanged();
}
};
asyncTask.execute(id);
}
现在我已经包含了一个搜索功能来过滤数据。
一旦用户输入搜索字符串,我希望recyclerview仅显示已过滤的项目,但它不起作用,recyclelerview不会更改其内容。
如何使用新内容重新制作Recyclerview?
答案 0 :(得分:0)
如果您已成功实施搜索,请执行以下操作,
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
***SOME UNIQUE OBJECT*** = (***SOME UNIQUE OBJECT TYPE***) session.save(***SOME UNIQUE OBJECT***);
session.getTransaction().commit();
} catch (HibernateException e) {
if (transaction != null) {
transaction.rollback();
}
} finally {
session.close();
}
return ***SOME UNIQUE OBJECT***;
注意:我认为即使在搜索完成后,适配器中的集合内容也没有变化,// Update your adapter collection with the filtered data.
adapter.notifyDataSetChanged();
将在初始状态下使用相同的集合执行它的工作。