项目积累2

 

7 列表 

2个xml
 1个是list的风格
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TextView01"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:textSize="17dp"
    android:textStyle="bold"   
    android:singleLine="true"
    android:gravity="center_vertical"
    android:text="@string/app_name"/>

 1个是显示list的activity的风格
其中要有个
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
 android:layout_height="wrap_content" android:gravity="left|top"
 android:divider="#22ffffff"  // 间隔条的颜色
 android:dividerHeight="1px"  // 间隔条的高度
 android:cacheColorHint="#00000000" />

java:
private List<String> myList = new ArrayList<String>(); 
private ArrayAdapter<String> mylistAdapter;
private File myderpath;

private ListView myListView;
myListView = (ListView)findViewById(android.R.id.list);
myListView.setOnItemLongClickListener(this);

private void showSoundList() {
 // TODO Auto-generated method stub
 myList.clear(); 
  
 if(myderpath.listFiles(new myfileter()).length > 0){
  //添加listname到list string
  for(File file : myderpath.listFiles(new Musicfileter())){
   myList.add(file.getName());  
  }
  
  //Adaper适配器
  mylistAdapter = new ArrayAdapter<String>(xxxx.this, R.layout.list, myList); //R.layout.list 就是list的风格
  //捆绑到listview
  myListView.setAdapter(mylistAdapter);
 }
 else{
  showemptytext.setVisibility(View.VISIBLE);
 }
  
 }

//匹配文件
class myfileter implements FilenameFilter {
  
 @Override
 public boolean accept(File arg0, String arg1) {
  // TODO Auto-generated method stub
  return (arg1.endsWith(".xxx") || arg1.endsWith(".xxx")
   || arg1.endsWith(".xxx") || arg1.endsWith(".xxx"));
 }
  
}

//点击列表
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
  
 // TODO Auto-generated method stub
 super.onListItemClick(l, v, position, id);
 
 ......
  
}

//长按列表
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int arg2,
  long arg3) {
  // TODO Auto-generated method stub
  //file title
  
  .......
  .......

  return false;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值