Pavle_nis

list

Feb 1st, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. public void listView()
  2.     {
  3.         textView = (TextView) getView().findViewById(R.id.textView_count);
  4.         int count;
  5.         String dirPath = "/sys/bus/usb/devices";
  6.         File dir = new File(dirPath);
  7.         File[] filelist = dir.listFiles();
  8.         String[] theNamesOfFiles = new String[filelist.length];
  9.         for (int i = 0; i < theNamesOfFiles.length; i++)
  10.         {
  11.             theNamesOfFiles[i] = filelist[i].getName();
  12.         }
  13.  
  14.         listView = (ListView) getView().findViewById(R.id.listView);
  15.         ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, theNamesOfFiles);
  16.         listView.setAdapter(arrayAdapter);
  17.  
  18.         listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
  19.  
  20.         count = listView.getAdapter().getCount();
  21.         textView.setText(count);
  22.  
  23.                 listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
  24.         {
  25.             @Override
  26.             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
  27.             {
  28.                 Intent intent = new Intent(getActivity(),USBInfoAPI.class);
  29.                 startActivity(intent);
  30.             }
  31.         });
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment