android中的搜索功能?

android中的搜索功能?,android,android-listview,android-searchmanager,Android,Android Listview,Android Searchmanager,我的阵列像{“Samsung Tab”,“Samsung Note”,“Samsung Galaxy”,“Samsung Galaxy Pro”,“Nokia Lumia”,“Nokia 5130”,“Sony Xperia”}之类的东西。我编辑文本类型Galaxy,然后单击按钮我有GO我只想显示Samsung Galaxy,三星Galaxy Pro在下一个活动列表视图中。如果您知道,请帮助我。有一些方法可以做到这一点,这里有一种方法,您可以创建如下所示的自定义方法 public ArrayL

我的阵列像{“Samsung Tab”,“Samsung Note”,“Samsung Galaxy”,“Samsung Galaxy Pro”,“Nokia Lumia”,“Nokia 5130”,“Sony Xperia”}之类的东西。我编辑文本类型Galaxy,然后单击按钮我有GO我只想显示Samsung Galaxy,三星Galaxy Pro在下一个活动列表视图中。如果您知道,请帮助我。

有一些方法可以做到这一点,这里有一种方法,您可以创建如下所示的自定义方法

 public ArrayList<String> getSearchedItems(String searchString){
 ArrayList<String>  list = new ArrayList<String>();

 for(int i = 0; i<array.length ;i++) { // array is the String array or list which contains all the Phone model names you want to search in.
  if((array[i].toLowerCase()).contains(searchString.toLowerCase())) { // contains method will check if user enterred string is available in your Model names
    list.add(array[i]);
    }
 }
 return list; // list of strings/names containing search String.
}
public ArrayList getSearchedItems(String searchString){
ArrayList=新建ArrayList();
对于(int i=0;i试试这个

  public class MainActivity extends Activity {

ArrayList<String> list = new ArrayList<String>();

private EditText searchEdt;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // making it full screen
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_ugsimply_beta);
    list.add("Samsung Tab");
    list.add("Samsung Note");
    list.add("Nokia Lumia");
    list.add("Nokia 5130");
    list.add("Sony Xperia");
    searchEdt = (EditText) findViewById(R.id.searchEdt);
    searchEdt.addTextChangedListener(new TextWatcher() {

        private int textlength;
        private ArrayList<String> arrayList_sort = new ArrayList<String>();

        public void afterTextChanged(Editable s) {
            // Abstract Method of TextWatcher Interface.
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // Abstract Method of TextWatcher Interface.
        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            textlength = searchEdt.getText().length();
            if (arrayList_sort != null)
                arrayList_sort.clear();

            for (int i = 0; i < list.size(); i++) {

                if (textlength <= list.get(i).toString().length()) {

                    if (searchEdt
                            .getText()
                            .toString()
                            .equalsIgnoreCase(
                                    (String) list.get(i).toString()
                                            .subSequence(0, textlength))) {
                        arrayList_sort.add(list.get(i));
                        Log.d("TAG", "log" + arrayList_sort.size());
                    }
                }
            }

        }
    });

}

试试这个,使用
TextWatcher
它会对你有所帮助。[单击此处][1][1]:单击第一个活动中的按钮后,它将转到第二个活动,并在第二个活动中显示Samsung Galaxy、Samsung Galaxy Pro列表视图。嗨,yugesh,我已经发布了示例代码。请尝试它。请不要忽略大写或小写。我们必须以大写字母表示名称,小写字母表示小写字母。其他方面,它不是acc您不明白吗?您可以始终使用另一个if条件来检查大写字母,例如数组[i].contains(stringSearch.toUpperCase())我希望你能给出一个与案例无关的结果,我希望你能给出一个与案例无关的结果。检查我编辑的答案。也尝试一些逻辑作为我们的要求,我们不能提供精确的解决方案,不是吗?例如,Mac Mini意味着如果我给Mini,它不是搜索。如果我给出确切的名字Mini,我会显示。正如我所说,为什么不将两个字符串都转换为大写或小写并不重要,而且在任何情况下都会返回true。
Intent i = new Intent(MainActivity.this,NextActivity.class);

i.putStringArrayListExtra("arraylist", arrayList_sort);
startActivity(i);