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);
}
'getDir()'開始'm_result'的值是什麼?你能把問題縮小到getDir()或doInBackground()嗎? – Michelle
其顯示所有文件先生列表視圖不顯示單元格中的第一條記錄,但當我點擊第一個單元格時,我得到所需結果 –
我面臨的問題是列表視圖不顯示第一個單元格中的第一個條目, 4 dots overthere –