السلام عليكم..
لدي لست فيو متصله بقاعدة البيانات عن طريق ملف json وأريد أن أعمل لها فلتر عن طريق الإديت تكست بحيث أن المستخدم يدخل أي حرف للبحث داخل اللست فيو بحيث يكون داخل onTextChanged
كيف الطريقة لوسمحتم بدون أي تعديل أو اضافة على ملف الادابتر؟
Telephones.class
public class Telephones extends AppCompatActivity {
RequestQueue requestQueue;
private List<tel_list> data = new ArrayList<tel_list>();
private ListView listView;
private TelAdapter adapter;
private EditText telfilter;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_telephones);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.actionbar);
listView = (ListView) findViewById(R.id.listview1);
adapter = new TelAdapter(this, data);
listView.setAdapter(adapter);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("الرجاء الإنتظار");
progressDialog.show();
telfilter = (EditText) findViewById(R.id.myFilter);
telfilter.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
requestQueue = Volley.newRequestQueue(this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, "
http://10.0.2.2/aa/getphone... ", new com.android.volley.Response.Listener() {
@Override
public void onResponse(JSONObject response) {
hideprogressDialog();
try {
JSONArray jsonArray = response.getJSONArray("telephones");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject telephones = jsonArray.getJSONObject(i);
tel_list tellist = new tel_list();
tellist.setName(telephones.getString("name"));
tellist.setNumber(telephones.getString("number"));
data.add(tellist);
}
} catch (JSONException e) {
e.printStackTrace();
}
adapter.notifyDataSetChanged();
}
},
new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
hideprogressDialog();
Log.e("Volley", "Error");
}
}
);
requestQueue.add(jsonObjectRequest);
}
@Override
public void onDestroy() {
super.onDestroy();
hideprogressDialog();
}
private void hideprogressDialog() {
if (progressDialog != null) {
progressDialog.dismiss();
progressDialog = null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.about:
Intent intent = new Intent(this, about.class);
startActivity(intent);
return true;
case R.id.contact:
Intent intent1 = new Intent(this, Contact.class);
startActivity(intent1);
return true;
}
return super.onOptionsItemSelected(item);
}
}
TelAdapter.class
public class TelAdapter extends ArrayAdapter {
private Context context;
private List<tel_list> telephones;
public TelAdapter(Context context, List<tel_list> data) {
super(context, R.layout.activity_item, data);
telephones = data;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View item = inflater.inflate(R.layout.activity_item, null);
TextView name = (TextView) item.findViewById(R.id.names);
name.setText(telephones.get(position).getName());
TextView number = (TextView) item.findViewById(R.id.numbers);
number.setText(telephones.get(position).getNumber());
return item;
}
}
التعليقات