यहां कोड है, मैंने कस्टम एडाप्टर का उपयोग किया है, और फ़िल्टर विधि लागू की है, अब बैकस्पेस कुंजी दर्ज होने पर ListView अपडेट नहीं होता है, जब कोई वापस से स्विच करता है एक वस्तु गतिविधि। मैंने पढ़ा है कि यह फिल्टर में एक बग है, लेकिन मैं इसे कैसे बाईपास कर सकता हूं, मुझे उन ऐप्स के बारे में पता है जिन्होंने इस तरह के सेटअप को हासिल किया है।फ़िल्टरिंग में बग को बाईपास करना जो सूची दृश्य को अपडेट नहीं करता है
public class IndexPageActivity extends Activity implements OnItemClickListener{
ListView listView;
EditText editTextB;
PagesAdapter adapter1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.pageList);
editTextB = (EditText) findViewById(R.id.searchB);
adapter1 = new PagesAdapter(this);
listView.setAdapter(adapter1);
adapter1.notifyDataSetChanged();
listView.setOnItemClickListener(this);
editTextB.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
IndexPageActivity.this.adapter1.getFilter().filter(cs.toString());
adapter1.notifyDataSetChanged();
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) { }
@Override
public void afterTextChanged(Editable arg0) { }
});
}
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
Intent i;
String name = adapter1.getItem(position);
Log.d("id", name);
if (name.equals("Item1"))
{
i = new Intent(this, anActivity.class);
startActivity(i);
}
else if (name.equals("Item2"))
{
i = new Intent(this, anActivity2.class);
startActivity(i);
}
}
}
class SingleRow {
String pagedata;
SingleRow(String pagedata){
this.pagedata=pagedata;
}
}
class PagesAdapter extends BaseAdapter implements Filterable{
ArrayList<String> pagelist;
List<String> arrayList;
Context context;
String [] pagedatas;
PagesAdapter(Context c){
context=c;
pagelist = new ArrayList<String>();
Resources res = c.getResources();
pagedatas = res.getStringArray(R.array.pages_data);
for (int i=0;i<463;i++){
pagelist.add(pagedatas[i]);
}
}
@Override
public int getCount() {
return pagelist.size();
}
@Override
public String getItem(int i) {
return pagelist.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewG) {
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.single_row,viewG,false);
TextView pagetitle = (TextView) row.findViewById(R.id.textViewRow);
String temp=pagelist.get(i);
pagetitle.setText(temp);
return row;
}
public class filter_here extends Filter{
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults Result = new FilterResults();
// if constraint is empty return the original names
if(constraint.length() == 0){
Result.values = pagelist;
Result.count = pagelist.size();
return Result;
}
ArrayList<String> Filtered_Names = new ArrayList<String>();
String filterString = constraint.toString().toLowerCase();
String filterableString;
for(int i = 0; i<pagelist.size(); i++){
filterableString = pagelist.get(i);
if(filterableString.toLowerCase().contains(filterString)){
Filtered_Names.add(filterableString);
}
}
Result.values = Filtered_Names;
Result.count = Filtered_Names.size();
return Result;
}
@Override
protected void publishResults(CharSequence constraint,FilterResults results) {
pagelist = (ArrayList<String>) results.values;
notifyDataSetChanged();
}
}
@Override
public Filter getFilter() {
return new filter_here();
}
}
धन्यवाद, मैं इनपुट को यह जा रहा हूँ और जल्द से जल्द आपके पास वापस! बहुत बहुत धन्यवाद .. आपको सभी क्रेडिट्स कोडरजी! –
मुझे बताओ क्या यह काम करता है ?! – Coderji
हाँ कोडरजी! यह काम करता है, एक और चीज तब आई, जब मैं इनपुट टेक्स्ट में ट्विंकल कहता हूं, यह आइटम को संबंधित करता है, जब मैं बैकस्पेस का उपयोग उन सभी को हटाने के लिए करता हूं, तो प्रदर्शित सूची पहले अक्षर "टी" से शुरू होने वाली वस्तुओं का होगा। ट्विंकल में वही अगर चॉकलेट संपादन टेक्स्ट में इनपुट था, बैकस्पेस्ड होने पर, केवल "सी" से शुरू होने वाली वस्तुओं को सूची दृश्य में प्रदर्शित किया जाता है। बॉस के बावजूद अच्छा काम! –