コード例 #1
0
		public void onClick(View v) {
			
			switch (v.getId()) {
			case R.id.btn_scan_add:
				//添加扫描目录
				Intent addit=new Intent(ScanDirectoryActivity.this,ScanMusicActivity.class);
				addit.putExtra("rs", adapter.getCheckFilePath());
				setResult(ScanMusicActivity.SCAN_MUSIC_OK, addit);
				finish();
				break;
			case R.id.btn_scan_directory_goup:
				//判断是否是父级目录
				if(!currrentFile.getPath().toLowerCase().equals(rootFilePath)){
					currrentFile=currrentFile.getParentFile();
					getFilePath(currrentFile);
					adapter.notifyDataSetChanged();
				}
				break;
			case R.id.btn_scan_back:
				setResult(-1);
				finish();
				break;
			default:
				break;
			}
		}
コード例 #2
0
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			//进入下一级目录
			currrentFile=files[position];
			rs=adapter.getCheckFilePath();
			getFilePath(currrentFile);
			adapter.notifyDataSetChanged();
		}
コード例 #3
0
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.scan_music_adddirectory);
		
		resultCode=ScanMusicActivity.SCAN_MUSIC_CANCEL;
		setBackButton();
		setTopTitle(getResources().getString(R.string.scan_directory_title));
		
		//检测SD卡
		if(!Common.isExistSdCard()){
			Toast.makeText(this, "请先插入SD卡", Toast.LENGTH_SHORT).show();
			setResult(RESULT_CANCELED);
			this.finish();
		}
		
		lv_scan_music_list=(ListView)this.findViewById(R.id.lv_scan_music_list);
		
		((Button)this.findViewById(R.id.btn_scan_add)).setOnClickListener(listener);
		((Button)this.findViewById(R.id.btn_scan_back)).setOnClickListener(listener);
		((Button)this.findViewById(R.id.btn_scan_directory_goup)).setOnClickListener(listener);

		//获取默认音乐目录的选取结果
		rs=getIntent().getStringExtra("rs");
		
		//读取mnt根目录
		myFilterFile=new ScanMusicFilterFile();
		lv_scan_music_list=(ListView)this.findViewById(R.id.lv_scan_music_list);
		currrentFile=Environment.getExternalStorageDirectory().getParentFile();//获取sd卡路径的父目录文件
		rootFilePath=currrentFile.getPath().toLowerCase();//设置根目录的路径
		data=new ArrayList<ScanData>();
		getFilePath(currrentFile);//遍历目录
		adapter=new ScanListAdapter(this,data);
		adapter.setCheckFilePath(rs);
		lv_scan_music_list.setAdapter(adapter);
		lv_scan_music_list.setOnItemClickListener(itemClickListener);
	}