Skip to content Skip to sidebar Skip to footer

Reading Files From A Custom Function Is Fc The App

I have the following code: final RelativeLayout mFrame3 = (RelativeLayout) inflater.inflate( R.layout.ptrip, container, false ); folder = new File(Environment.g

Solution 1:

Your GetFileData function is creating a HashMap not an ArrayList. You can not get an element from a HashMap by using its position. Instead individual Hashmap entries are obtained by passing its key (Here is key is filename itself). So you actually need a reference to the hashmap entry. You can use setTag() and getTag() functions of View class to achieve that.

few other alternatives you can try are

  1. use findViewbyId

    dataList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    publicvoidonItemClick(AdapterView<?> parent, View v, int position, long id) {
    
    
    TextView clicked= (TextView) v.findViewById(R.id.id_of_textview_that_hold_filename);
    String current_file=clicked.getText().toString();
    
    } 
    
  2. Try to get filename from rowsArray using position. You may need to use an intermediate final variable to make rowsArray accessible inside listener

  3. Make FilesData an ArrayList that holds a string array of size 2.

Inside GetFileData method, create a new string array of size two, store filename and modification date to position 0 & 1. Then add this string array to the array list. You need to change necessary variables from HashMap to ArrayList

Solution 2:

FilesInFolder is now a Hashmap, so you just want to get the filename at a given position (index), which is the first element of the map - the keys (the 2nd is the timestamp, or values of the map). So you could do something like this:

First convert the map keys to a list:

List<Value> filenames = newArrayList<String>(FilesInFolder.keys());

then:

File flEachFile = new File(folder.toString()+ "/" + filenames.get(position).toString());

Post a Comment for "Reading Files From A Custom Function Is Fc The App"