Advertisement
thieumao

SelectActivity - temp

May 12th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. package com.doan.quet;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.AdapterView;
  9. import android.widget.ArrayAdapter;
  10. import android.widget.ListView;
  11. import android.widget.TextView;
  12.  
  13. import java.io.File;
  14. import java.util.ArrayList;
  15.  
  16. public class SelectActivity extends AppCompatActivity {
  17.  
  18.     ArrayList<String> listView = new ArrayList<String>();
  19.     ArrayList<String> listFile = new ArrayList<String>();
  20.     String Path = "";
  21.     String PathTemp = "/";
  22.     String PathParent = "/";
  23.     TextView txt;
  24.     ListView lv;
  25.     ArrayAdapter<String>adapter;
  26.  
  27.     protected void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.activity_select);
  30.         txt=(TextView) findViewById(R.id.txtselection);
  31.         lv=(ListView) findViewById(R.id.list);
  32.  
  33.         ChangeSelect(PathTemp);
  34.  
  35.         lv.setOnItemClickListener(
  36.                 new AdapterView.OnItemClickListener() {
  37.                     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
  38. //                        txt.setText("position :"+arg2+" ; value ="+ listFile.get(arg2));
  39.                         try {
  40.                             PathTemp = Path;
  41.                             Path = Path + "/" + listFile.get(arg2);
  42.                             ChangeSelect(Path);
  43.                         } catch(Exception e){}
  44.                     }
  45.                 }
  46.         );
  47.     }
  48.  
  49.     void ChangeSelect(String path){
  50.         File directory = new File(path);
  51.         listFile = new ArrayList<String>();
  52.         listView = new ArrayList<String>();
  53.         File[] files = directory.listFiles();
  54.         for (int i = 0; i < files.length; ++i) {
  55.             listFile.add(files[i].getName());
  56.             if (files[i].isDirectory()){
  57.                 listView.add("Folder -- " + files[i].getName());
  58.             } else {
  59.                 listView.add("File   -- " + files[i].getName());
  60.             }
  61.         }
  62.         txt.setText(path);
  63.         adapter=new ArrayAdapter<String>
  64.                 (this, android.R.layout.simple_list_item_1, listView);
  65.         lv.setAdapter(adapter);
  66.     }
  67.  
  68.     public void Back(View view) {
  69.         Log.v("mao", "mao back");
  70.         ChangeSelect(PathTemp);
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement