痴人没梦 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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘