痴人没梦 2017-07-21 05:08 采纳率: 0%
浏览 734

为什么这个搜索结果textview显示,listview不显示呢?

就是网上安卓变量sd卡搜索文件的代码
上代码:
package com.mycompany.myapp;

import android.app.*;
import android.os.*;
import java.util.*;
import android.widget.*;
import java.io.*;

public class MainActivity extends Activity
{

private String keywrod = "txt";

private File files;
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    files = new File("/sdcard/"); 

                    SimpleAdapter saImageItems = new SimpleAdapter(this,
                                                   getData(),// 数据来源
                                                   R.layout.user,//每一个user xml 相当ListView的一个组件 
                                                   new String[] { "name", "age" },
                                                   // 分别对应view 的id
                                                   new int[] {  R.id.name, R.id.age });
    // 获取listview
    ((ListView) findViewById(R.id.users)).setAdapter(saImageItems);
    }

List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

private List<Map<String, Object>> getData()//获取数据集给予list
{




    return list;
}



private void search(File fileold)
{
            try{
        File[] files=fileold.listFiles();
        if(files.length>0)
                {
                    HashMap<String, Object> user = new HashMap<String, Object>();
            for(int j=0;j<files.length;j++)
            {
                if(!files[j].isDirectory())
                {
                    if(files[j].getName().indexOf(keywrod)> -1)
                    {
                            //  path += "\n" + files[j].getPath(); 
                        //result.setText(info+path);
                        user.put("age",files[j].getName());

                        user.put("name",files[j].getPath());
                        list.add(user);
                        //shuju.putString(files[j].getName().toString(),files[j].getPath().toString());
                    }
                }
                else{
                    this.search(files[j]);
                }
            }
        }
    }
    catch(Exception e)
    {   }
}

}

main.xml

<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
    android:text="用户列表"
    android:gravity="center"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:background="#DAA520"
    android:textColor="#000000">

</TextView>

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/users"

    android:background="#D07873">

</ListView>

user.xml

<?xml version="1.0" encoding="utf-8"?>

<TableLayout

android:layout_width="fill_parent"

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_height="wrap_content"

<TableRow > 
    <ImageView    
        android:layout_width="wrap_content"    
        android:layout_height="wrap_content"   
        android:id="@+id/img">    
    </ImageView>  
    <TextView    
        android:layout_height="wrap_content"    
        android:layout_width="150px"    
        android:id="@+id/name">  
    </TextView>  
    <TextView    
        android:layout_height="wrap_content"   
        android:layout_width="170px"    
        android:id="@+id/age">  
    </TextView> 
</TableRow> 

  • 写回答

4条回答 默认 最新

  • artqi 2017-07-21 05:19
    关注

    暂时不知道 抱歉

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog