Android:在listview中显示app中文件的名称

时间:2014-04-29 03:01:46

标签: android

我尝试显示资产文件夹中的文件列表,但它没有显示,在调试时我发现适配器为空并启动空白活动。为什么它不知道,也无法找到我做过的任何错误。我是这个领域的新手,任何信息都将受到赞赏

public class JobListActivity extends Activity {

private ListView m_JobListView;
private String[] m_Filename;
private String m_Path;
private ArrayList<String> m_JobList;
private ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    m_JobListView = (ListView) findViewById(R.id.joblistView1);
    m_Path = "file:///android_asset/";

}

@Override
protected void onResume() {
    super.onResume();

    m_JobList = new ArrayList<String>();
    m_JobListView = (ListView) findViewById(R.id.joblistView1);
    adapter = new ArrayAdapter<String>(JobListActivity.this,
            R.layout.activity_joblist, android.R.id.text1, m_JobList);
    try {
        m_Filename = getAssets().list("file:///android_asset/");

        if (m_Filename != null && (null != m_JobList)) {

            for (int i = 0; i < m_Filename.length; i++) {
                m_JobList.add(m_Filename[i]);
            }

            if ((m_Filename.length == 0) || (null == m_Filename)) {
                m_JobList.add(0, "No sheets available");
            }
        }



        if (adapter != null) {
            if (m_JobListView != null) {
                if (m_JobList != null) {
                    m_JobListView.setAdapter(adapter);
                    adapter.notifyDataSetChanged();
                }
            }

        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}

1 个答案:

答案 0 :(得分:1)

  

m_Filename = getAssets()。list(&#34; file:/// android_asset /&#34;);

通过以下行替换此行

  

m_Filename = getAssets()。list(&#34;&#34;);