2013-08-21 81 views
0

我在列表視圖中顯示來自服務器的所有文件。Listview不顯示第一項

文件服務器上的如下: binary.txt/erpTestBench/muneem.php/oglPrahova/permitCore/workOrderTestBench/

列表視圖中顯示,除了binary.txt文件中的所有文件。

我的列表視圖的XML文件如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
     > 


    <TextView 
      android:id="@+id/path" 
      android:layout_width="fill_parent" 
      android:textSize="12dp" 
      android:layout_height="wrap_content" android:background="#2377ff"/> 
    <ListView 
      android:id="@android:id/list" 
      android:cacheColorHint="#00000000" 
      android:layout_width="fill_parent" 
      android:layout_height="70dp" 
      android:layout_weight="0.85" 
      android:clickable="false" 
      android:textSize="30dp" 
      android:drawSelectorOnTop="false" android:background="#2f3fc8" android:layout_gravity="center" 
      android:dividerHeight="15dp"/> 
    <TextView 
      android:id="@android:id/empty" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="30dp" 
      android:text="No Data" 
      android:layout_weight="0.75" 
      android:background="#2f3fc8"/> 

    <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:paddingTop="6dp" android:paddingBottom="6dp" android:gravity="center|center_vertical" 
      android:id="@+id/linearLayout" android:background="#346684"> 

     <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageView1" 
       android:src="@drawable/power" 
       android:onClick="bt_Quit" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" 
       android:layout_gravity="center"/> 
     <ImageView 
       android:layout_width="80dp" 
       android:layout_height="fill_parent" 
       android:id="@+id/imageView4" 
       android:src="@drawable/back" 
       android:onClick="back" 
       android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/> 
     <ImageView 
       android:layout_width="71dp" 
       android:layout_height="fill_parent" 
       android:id="@+id/imageView2" 
       android:src="@drawable/home" 

       android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:onClick="home"/> 
    </LinearLayout> 




</LinearLayout> 

我的java文件如下:

public class serv extends ListActivity { 
    private String m_urlString="XXXXX"; 
// private String result; 

    private List<String> m_item = null; 
    private List<String> m_path = null; 
    private String m_root="XXXX"; 
    private String m_result; 
    private TextView m_myPath; 
    static private String m_pos; 
    private String m_backposition; 
    private String m_fileURL; 


    int m_downloadedSize = 0; 
    int m_totalSize = 0; 



    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.file_chooser); 

     View v= findViewById(R.id.rowtext); 


     m_myPath = (TextView)findViewById(R.id.path); 
     m_fileURL="http://192.168.1.30/muneem/"; 
     Http_connection f=new Http_connection(); 
     f.execute(""); 


    } 

    class Http_connection extends AsyncTask<String, Void, Void> { 

     private Exception exception; 

     protected Void doInBackground(String... urls) 
     { 

      try 
      { 
       URL url= new URL(m_urlString); 
       HttpURLConnection con=(HttpURLConnection)url.openConnection(); 
       con.setRequestMethod("GET"); 
       con.connect(); 
       int statusCode=con.getResponseCode(); 
       if (statusCode==HttpURLConnection.HTTP_OK){ 
        BufferedReader in= new BufferedReader(new InputStreamReader(con.getInputStream())); 
        String line; 
        m_result=""; 
        while ((line=in.readLine())!=null) 
        { 
         m_result=m_result+"\n"+line; 
        } 
        in.close(); 
        con.disconnect(); 
        runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          getDir(m_urlString); 


         } 
        }); 

       } 
      } 
      catch (MalformedURLException e) 
      { 
       //   bundle.putString("Error","Problem with URL"); 

      } 
      catch (IOException e) 
      { 
       //    bundle.putString("Error","Problem with connection"); 

      } 


      return null; 
     } 
    } 
    private void getDir(String dirPath) 
    { 


     String[] r=m_result.split("/"); 
     m_myPath.setText("Location: " + dirPath); 
     m_item = new ArrayList<String>(); 
     m_path = new ArrayList<String>(); 

     for (int k=0;k<r.length;k++) 
     { 
      if (r[k].contains(".")) 
      { 
       m_item.add(r[k]); 

      } 
      else 
      { 
       m_item.add(r[k]+"/"); 
      } 
     } 


     ArrayAdapter<String> fileList = 
       new ArrayAdapter<String>(serv.this, R.layout.row, m_item); 
     setListAdapter(fileList); 

    } 
+0

'getDir()'開始'm_result'的值是什麼?你能把問題縮小到getDir()或doInBackground()嗎? – Michelle

+0

其顯示所有文件先生列表視圖不顯示單元格中的第一條記錄,但當我點擊第一個單元格時,我得到所需結果 –

+0

我面臨的問題是列表視圖不顯示第一個單元格中的第一個條目, 4 dots overthere –

回答

0

您的數據經過幾個步驟做它到ListView之前,因此源問題可能是幾個不同步驟之一。如果您調試您的代碼並在getDir()開頭檢查m_result的值,則可以確定問題來自何處。如果該值與預期的一樣,則getDir()中可能存在問題,而如果字符串出現問題,則問題可能在doInBackground()(如果知道結果有什麼問題,則很容易發現問題)。