我在 AsyncTask 中用 ArrayAdapter 填充 ListView。但每次它只填写一项。
有人可以解释我为什么吗?
创建
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.connected_download);
Log.v("string", "test6");
runOnUiThread(new Runnable() {
public void run() {
str_profil = getIntent().getStringExtra("profil");
str_server = getIntent().getStringExtra("server");
str_port = getIntent().getStringExtra("port");
str_user = getIntent().getStringExtra("user");
str_password = getIntent().getStringExtra("pw");
new connection_test().execute();
}
});
}
异步任务
private class connection_test extends AsyncTask<String, Void, String> {
protected void onPreExecute(){
dialog = ProgressDialog.show(connected_download.this, null, "Erstelle Vorschau. Bitte warten...");
}
protected String doInBackground(String... connection) {
listftpitems();
return null;
}
protected void onPostExecute(String result) {
dialog.dismiss();
}
}
列表文件
public void listftpitems(){
try {
ftpClient.setConnectTimeout(15000);
Integer int_port = Integer.parseInt(str_port);
ftpClient.connect(InetAddress.getByName(str_server), int_port);
ftpClient.login(str_user, str_password);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
System.out.println("status :: " + ftpClient.getStatus());
System.out.println("FTPClient : " + "Offen");
} catch (Exception e) {
e.printStackTrace();
}
final ArrayList<String> your_array_list = new ArrayList<String>();
final ListView lv = (ListView) findViewById(R.id.list_download);
final FTPFile[] files;
try {
files = ftpClient.listFiles();
for (FTPFile file : files) {
String details = file.getName();
your_array_list.add(details);
Log.v("string", details);
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(connected_download.this,android.R.layout.simple_list_item_1, your_array_list);
runOnUiThread(new Runnable() {
public void run() {
lv.setAdapter(arrayAdapter);
}
});
}catch (IOException e1) {
e1.printStackTrace();
}
}
LogCat(查看 Log.v("string", details); on listftpitems)所以它是正确的
12-05 11:34:24.650: D/AbsListView(23249): Get MotionRecognitionManager
12-05 11:34:24.650: V/string(23249): test6
12-05 11:34:24.695: D/dalvikvm(23249): GC_FOR_ALLOC freed 64K, 9% free 13420K/14599K, paused 13ms, total 15ms
12-05 11:34:24.945: D/dalvikvm(23249): GC_CONCURRENT freed 29K, 8% free 13813K/14983K, paused 11ms+5ms, total 28ms
12-05 11:34:25.480: I/System.out(23249): status :: 211-Status of 'ProFTPD'
12-05 11:34:25.480: I/System.out(23249): Connected from 213.55.184.193 (213.55.184.193)
12-05 11:34:25.480: I/System.out(23249): Logged in as ftp031220
12-05 11:34:25.480: I/System.out(23249): TYPE: BINARY, STRUcture: File, Mode: Stream
12-05 11:34:25.480: I/System.out(23249): No data connection
12-05 11:34:25.480: I/System.out(23249): 211 End of status
12-05 11:34:25.480: I/System.out(23249): FTPClient : Offen
12-05 11:34:26.095: V/string(23249): anon_ftp
12-05 11:34:26.095: V/string(23249): bin
12-05 11:34:26.095: V/string(23249): cgi-bin
12-05 11:34:26.095: V/string(23249): conf
12-05 11:34:26.095: V/string(23249): error_docs
12-05 11:34:26.095: V/string(23249): httpdocs
12-05 11:34:26.095: V/string(23249): httpsdocs
12-05 11:34:26.095: V/string(23249): mivadata
12-05 11:34:26.095: V/string(23249): pd
12-05 11:34:26.095: V/string(23249): private
12-05 11:34:26.095: V/string(23249): statistics
12-05 11:34:26.095: V/string(23249): subdomains
12-05 11:34:26.095: V/string(23249): vault_scripts
12-05 11:34:26.095: V/string(23249): web_users
我手机里的照片