を拡張するListViewAdapter
を使用して、結果をListView
に表示しています。出力を表示するには、ListView
に3 TextView
があります。 searchviewを実装したいのですが、検索バーに入力すると画面が空白になります。どのように実装するのですか?私はaddTextChangedListener
もEditText
を使用してみましたが、何のoutput.Thisはあなたの結果を得るために濾過インタフェースを実装する必要があり、ここでActivity
multicolum listviewのsearchview
searchView = (SearchView)findViewById(R.id.searchView);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
return false;
}
});
}
private void loadDescriptionList() {
final ProgressDialog progressDialog = new ProgressDialog(TestDetails.this);
progressDialog.setMessage("Loading Data...");
progressDialog.show();
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response)
{
progressDialog.dismiss();
try {
JSONObject obj = new JSONObject(response);
JSONArray heroArray = obj.getJSONArray("list");
for (int i = 0; i < heroArray.length(); i++) {
JSONObject heroObject = heroArray.getJSONObject(i);
TDescription hero = new TDescription(heroObject.getString("test_code"), heroObject.getString("test_description"),heroObject.getString("test_price"));
heroList.add(hero);
}
adapter = new ListViewAdapter(heroList, getApplicationContext());
listView.setAdapter(adapter);
} catch (JSONException e) {
progressDialog.dismiss();
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
LISTVIEWADAPTER.JAVA
public class ListViewAdapter extends ArrayAdapter<TDescription> {
private List<TDescription> heroList;
private Context mCtx;
Typeface typeface;
TextView rup;
public ListViewAdapter(List<TDescription> heroList, Context mCtx) {
super(mCtx, R.layout.list_items, heroList);
this.heroList = heroList;
this.mCtx = mCtx;
typeface = Typeface.createFromAsset(mCtx.getAssets(), "fontawesome-webfont.ttf");
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(mCtx);
View listViewItem = inflater.inflate(R.layout.list_items, null, true);
TextView code = (TextView)listViewItem.findViewById(R.id.code);
TextView desc = (TextView)listViewItem.findViewById(R.id.desc);
TextView price = (TextView)listViewItem.findViewById(R.id.price);
rup = (TextView)listViewItem.findViewById(R.id.rupee);
rup.setTypeface(typeface);
TDescription hero = heroList.get(position);
code.setText(hero.getCode());
desc.setText(hero.getDesc());
price.setText(hero.getPrice());
return listViewItem;
}
移動に基づいてデータをフィルタリングし、独自のロジック –
を実装しますが、この[リンク](HTTPSで見てください。 com/questions/24769257/custom-listview-adapter-with-filter-android) –