There is a fragment in which the listview search is organized; help to display data from the file in it; I tried something wrong with the types.

Search phase

String[] items; ArrayList<String> listItems; ArrayAdapter<String> adapter; ListView listView; EditText editText; String textPos0, textPos1,textPos3; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(layout.fragment_search, container, false); getActivity().setTitle(R.string.fr2); listView=(ListView) rootView.findViewById(id.lst); editText=(EditText) rootView.findViewById(id.txtsearch); initList(); editText.clearFocus(); editText.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) { if(s.toString().equals("")){ // Обновление listview initList(); } else { // выполнение поиска searchItem(s.toString()); } } @Override public void afterTextChanged(Editable s) { } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view,int position, long id) { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); FragmentTransaction tr = getFragmentManager().beginTransaction(); String currPos = listItems.get(position); if (currPos.equals(textPos0)) { //Создание нового фрагмента и транзакции Fragment Stay1 = new Stay1(); // Замените все, что есть в представлении fragment_container, этим фрагментом, //И добавьте транзакцию в задний стек tr.replace(R.id.container, Stay1); tr.addToBackStack(null); //Завершить транзакцию tr.commit(); } else if (currPos.equals(textPos1)) { Fragment Stay2 = new Stay2(); tr.replace(R.id.container, Stay2); tr.addToBackStack(null); tr.commit(); } else if (currPos.equals(textPos3)){ Fragment Stay3 = new Stay3(); tr.replace(R.id.container, Stay3); tr.addToBackStack(null); tr.commit(); } } }); return rootView; } public List<String> getTextFromRaw() { List<String> strList = new ArrayList<>(); BufferedReader bufferedReader; try { InputStream inputStream = getResources().openRawResource(R.raw.stm); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line; int count = 0; while ((line = bufferedReader.readLine()) != null) { strList.add(line); count++; if (count==10){ break; } } bufferedReader.close(); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return strList; } public void searchItem(String textToSearch){ textToSearch = textToSearch.toLowerCase(); for(String item:items){ if(!item.toLowerCase().contains(textToSearch)){ listItems.remove(item); } } adapter.notifyDataSetChanged(); } //передача результатов поиска в listview public void initList(){ String [] arr1; List<String> arr = getTextFromRaw(); arr1 = getResources().getStringArray(R.array.stops); items=arr; listItems=new ArrayList<>(Arrays.asList(items)); adapter=new ArrayAdapter<String>(getActivity(), layout.list_item, id.txtitem, listItems); listView.setAdapter(adapter); textPos0 = listItems.get(0); textPos1 = listItems.get(1); textPos3 = listItems.get(9); } } items=arr; в этой строке incompatible types required: java.long string found java.util.list 
  • What errors and on what lines? - eugeneek
  • @eugeneek changed the code look - Grohovac
  • You equate sheet to an array. So it does not work. Change to items = arr.toArray(new String[arr.size()]); - eugeneek
  • @eugeneek thanks earned - Grohovac

0