从sdcard到listview创建了两个文件名和时间的文本视图
我的应用程序是我录制声音并在列表中显示录制文件的地方。我想创建一个包含两个文本视图的列表视图。我从sd卡中指定一个文件夹,其中包含我使用应用程序录制的音频文件,并在列表视图中显示这些文件。列表中的第一个文本视图是文件名,第二个文本是创建的时间或日期。我不知道如何在名单上加上时间 我的代码如下从sdcard到listview创建了两个文件名和时间的文本视图,listview,datetime,android-listview,arraylist,adapter,Listview,Datetime,Android Listview,Arraylist,Adapter,我的应用程序是我录制声音并在列表中显示录制文件的地方。我想创建一个包含两个文本视图的列表视图。我从sd卡中指定一个文件夹,其中包含我使用应用程序录制的音频文件,并在列表视图中显示这些文件。列表中的第一个文本视图是文件名,第二个文本是创建的时间或日期。我不知道如何在名单上加上时间 我的代码如下 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); set
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
recordstart = (Button)findViewById(R.id.button1);
recordstop = (Button)findViewById(R.id.button3);
recording = false;
recordstart.setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
// TODO Auto-generated method stub
AlertDialog.Builder alert = new AlertDialog.Builder(recordsound.this);
alert.setTitle("Add Name");
// Set an EditText view to get user input
final EditText input = new EditText(recordsound.this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
value = input.getText().toString();
// Do something with value!
System.out.println("value is"+ value);
if(value==""&&value==null){
recordstart.setVisibility(View.INVISIBLE);
listView.setVisibility(View.INVISIBLE);
recordstop.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(),"Please enter the name " +itemValue , Toast.LENGTH_LONG).show();
recordint=1;
}else{
recordstart.setVisibility(View.INVISIBLE);
listView.setVisibility(View.INVISIBLE);
recordstop.setVisibility(View.VISIBLE);
recordint=2;
}
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
timearray.add(today.format("%k:%M:%S"));
startRecording(v);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
startRecording(v);
}
});
recordstop.setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
stopRecording(v);
}
});
String cardRootnew = Environment.getExternalStorageDirectory().getAbsolutePath() + "/newrecorder/";
dataPathnew = cardRootnew;
File folder1 = new File(dataPathnew);
boolean success = false;
if (!folder1.exists()) {
success = folder1.mkdir();
}
if (!success) {
} else {
}
listView = (ListView) findViewById(R.id.mylist);
myList = new ArrayList<String>();
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
String cardRoot = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/newrecorder/" ;
dataPath = cardRoot;
File directory =new File(dataPath);
File file = new File( dataPath );
File list[] = file.listFiles();
for( int i=0; i< list.length; i++)
{
myList.add( list[i].getName() );
}
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, myList);
listView.setAdapter(adapter); //Set all the file in the list.
// ListView Item Click Listener
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
itemValue = (String) listView.getItemAtPosition(position);
String filepath=dataPath + itemValue;
Intent intent = new Intent(recordsound.this, FilesActivity.class);
intent.putExtra("filepath", filepath);
intent.putExtra("itemvalue", itemValue);
startActivity(intent);
// Show Alert
Toast.makeText(getApplicationContext(),
"Playing " +itemValue , Toast.LENGTH_LONG)
.show();
}
});
}
void playshit()
{
File sound = new File(dataPath + itemValue);
Uri soundUri = Uri.fromFile(sound);
MediaPlayer mediaPlayer = MediaPlayer.create(this, soundUri);
mediaPlayer.start();
}
private SeekBar getSeekBar(int id) {
SeekBar seekBar = (SeekBar) findViewById(id);
seekBar.setMax(MIDDLE * 2);
seekBar.setProgress(MIDDLE);
seekBar.setOnSeekBarChangeListener(this);
return seekBar;
}
public void startRecording(View view) {
if(recordint==1){
if (!recording) {
extAudioRecorder = ExtAudioRecorder.getInstanse(false);
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
extAudioRecorder.setOutputFile(dataPathnew +String.valueOf(today.format("%k:%M:%S")));
extAudioRecorder.prepare();
extAudioRecorder.start();
recording = true;
}
}else if(recordint==2){
if (!recording) {
extAudioRecorder = ExtAudioRecorder.getInstanse(false);
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
extAudioRecorder.setOutputFile(dataPathnew +value+String.valueOf(today.format("%k:%M:%S")));
extAudioRecorder.prepare();
extAudioRecorder.start();
recording = true;
if(timearray!=null){
System.out.println("today.format is"+ timearray.size());
}
}
}
}
public void stopRecording(View view) {
if (recording) {
extAudioRecorder.stop();
extAudioRecorder.release();
recording = false;
}
Intent intent = getIntent();
finish();
startActivity(intent);
}
public void playRecording(View view) {
File sound = new File(dataPathnew + "output.wav");
Uri soundUri = Uri.fromFile(sound);
MediaPlayer mediaPlayer = MediaPlayer.create(this, soundUri);
mediaPlayer.start();
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (seekBar.equals(rateBar)) {
rate = progress - MIDDLE;
} else if (seekBar.equals(tempoBar)) {
tempo = progress - MIDDLE;
} else if (seekBar.equals(pitchBar)) {
pitch = progress - MIDDLE;
}
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
recordstart=(按钮)findViewById(R.id.button1);
recordstop=(按钮)findViewById(R.id.button3);
记录=假;
recordstart.setOnClickListener(新的OnClickListener(){
公共void onClick(最终视图v){
//TODO自动生成的方法存根
AlertDialog.Builder alert=新建AlertDialog.Builder(recordsound.this);
alert.setTitle(“添加名称”);
//设置EditText视图以获取用户输入
最终编辑文本输入=新编辑文本(recordsound.this);
alert.setView(输入);
alert.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
public void onClick(对话框接口对话框,int whichButton){
value=input.getText().toString();
//做一些有价值的事情!
System.out.println(“值为”+值);
如果(值=“”&&value==null){
recordstart.setVisibility(视图不可见);
setVisibility(View.INVISIBLE);
recordstop.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(),“请输入名称”+itemValue,Toast.LENGTH_LONG).show();
recordint=1;
}否则{
recordstart.setVisibility(视图不可见);
setVisibility(View.INVISIBLE);
recordstop.setVisibility(View.VISIBLE);
recordint=2;
}
今日时间=新时间(Time.getCurrentTimezone());
今天;
timearray.add(今天的格式(“%k:%M:%S”);
开始记录(v);
}
});
alert.setNegativeButton(“取消”,新建DialogInterface.OnClickListener()){
public void onClick(对话框接口对话框,int whichButton){
//取消了。
}
});
alert.show();
开始记录(v);
}
});
setOnClickListener(新的OnClickListener(){
公共void onClick(最终视图v){
停止记录(v);
}
});
字符串cardRootnew=Environment.getExternalStorageDirectory().getAbsolutePath()+“/newrecorder/”;
dataPathnew=cardRootnew;
File folder1=新文件(dataPathnew);
布尔成功=假;
如果(!folder1.exists()){
success=folder1.mkdir();
}
如果(!成功){
}否则{
}
listView=(listView)findViewById(R.id.mylist);
myList=新的ArrayList();
今日时间=新时间(Time.getCurrentTimezone());
今天;
String cardRoot=Environment.getExternalStorageDirectory().getAbsolutePath()+“/newrecorder/”;
dataPath=cardRoot;
文件目录=新文件(数据路径);
文件文件=新文件(数据路径);
文件列表[]=File.listFiles();
for(int i=0;i