当前位置: 编程技术>移动开发
本页文章导读:
▪在市场中展示 在市场中显示
Uri marketUri = Uri.parse("market://details?id=com.metago.astro&feature=top-free");
Intent viewIntent = new Intent();
viewIntent.setData(marketUri);
startActivity(viewIntent);
......
▪ 内存储器映射文件性能对比测试 内存映射文件性能对比测试
今天对比了一下内存映射文件的性能和普通文件的测试,不比不知道,一比吓一跳啊。差距太大了。
public class FileTest {
static int length = 0x8000000; // 128 Mb
public.........
▪ 转:listView 增添多个不同的adapter 转:listView 添加多个不同的adapter
有时候我们想在listView上分类,或者呢 有时候一行显示两列内容,有时候需要三列内容 ,那怎么实现呢,这里呢就要使用
class Section {
String caption;
.........
[1]在市场中展示
来源: 互联网 发布时间: 2014-02-18
在市场中显示
Uri marketUri = Uri.parse("market://details?id=com.metago.astro&feature=top-free");
Intent viewIntent = new Intent();
viewIntent.setData(marketUri);
startActivity(viewIntent);
[2] 内存储器映射文件性能对比测试
来源: 互联网 发布时间: 2014-02-18
内存映射文件性能对比测试
今天对比了一下内存映射文件的性能和普通文件的测试,不比不知道,一比吓一跳啊。差距太大了。
public class FileTest {
static int length = 0x8000000; // 128 Mb
public void doMemTest() {
try {
long start = System.currentTimeMillis();
FileChannel fc = new RandomAccessFile("e:/test/test.dat", "rw").getChannel();
MappedByteBuffer out = fc.map(FileChannel.MapMode.READ_WRITE, 0, length);
for (int i = 0; i < length; i++) {
out.put((byte) 'x');
}
long end = System.currentTimeMillis();
fc.close();
System.out.println(end - start);
} catch (Exception e) {
e.printStackTrace();
}
}
public void doGeneralTest() {
try {
long start = System.currentTimeMillis();
RandomAccessFile fc = new RandomAccessFile("e:/test/test.dat", "rw");
for (int i = 0; i < length; i++) {
fc.write((byte) 'x');
}
long end = System.currentTimeMillis();
System.out.println(end - start);
fc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
FileTest t = new FileTest();
// t.doMemTest();
t.doGeneralTest();
}
}
doMemtest这个方法,1000多毫秒的样子,doGeneralTest这个基本就没跑完过。
1 楼
mysh
2012-02-03
这个不能说明内存映射比较快吧, 只能说明 nio 比 io 快, 要比较的话起码两个都用直接写数据块的方式, put(byte[]) write(byte[])
[3] 转:listView 增添多个不同的adapter
来源: 互联网 发布时间: 2014-02-18
转:listView 添加多个不同的adapter
有时候我们想在listView上分类,或者呢 有时候一行显示两列内容,有时候需要三列内容 ,那怎么实现呢,这里呢就要使用
class Section {
String caption;
Adapter adapter;
Section(String caption, Adapter adapter) {
this.caption=caption;
this.adapter=adapter;
}
}
自定义一个类,这个类呢包含多个adapter就可以了,想用那种就用那种。
abstract public class SectionedAdapter extends BaseAdapter {
abstract protected View getHeaderView(String caption,int index,View convertView,ViewGroup parent);
private List<Section> sections=new ArrayList<Section>();
private static int TYPE_SECTION_HEADER=0;
public SectionedAdapter() {
super();
}
public void addSection(String caption, Adapter adapter) {
sections.add(new Section(caption, adapter));
}
public Object getItem(int position) {
for (Section section : this.sections) {
if (position==0) {
return(section);
}
int size=section.adapter.getCount()+1;
if (position<size) {
return(section.adapter.getItem(position-1));
}
position-=size;
}
return(null);
}
public int getCount() {
int total=0;
for (Section section : this.sections) {
total+=section.adapter.getCount()+1; // add one for header
}
return(total);
}
public int getViewTypeCount() {
int total=1; // one for the header, plus those from sections
for (Section section : this.sections) {
total+=section.adapter.getViewTypeCount();
}
return(total);
}
public int getItemViewType(int position) {
int typeOffset=TYPE_SECTION_HEADER+1; // start counting from here
for (Section section : this.sections) {
if (position==0) {
return(TYPE_SECTION_HEADER);
}
int size=section.adapter.getCount()+1;
if (position<size) {
return(typeOffset+section.adapter.getItemViewType(position-1));
}
position-=size;
typeOffset+=section.adapter.getViewTypeCount();
}
return(-1);
}
public boolean areAllItemsSelectable() {
return(false);
}
public boolean isEnabled(int position) {
return(getItemViewType(position)!=TYPE_SECTION_HEADER);
}
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
int sectionIndex=0;
for (Section section : this.sections) {
if (position==0) {
return(getHeaderView(section.caption, sectionIndex,convertView, parent));
}
int size=section.adapter.getCount()+1;
if (position<size) {
return(section.adapter.getView(position-1, convertView,parent));
}
position-=size;
sectionIndex++;
}
return(null);
}
@Override
public long getItemId(int position) {
return(position);
}
class Section {
String caption;
Adapter adapter;
Section(String caption, Adapter adapter) {
this.caption=caption;
this.adapter=adapter;
}
}
}
然后主类就是
public class SectionedDemo extends ListActivity {
private static String[] items={"lorem", "ipsum", "dolor","purus"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
adapter.addSection("Original",new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
items));
List<String> list=Arrays.asList(items);
Collections.shuffle(list);
adapter.addSection("Shuffled",new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
list));
list=Arrays.asList(items);
Collections.shuffle(list);
adapter.addSection("Re-shuffled",new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
list));
setListAdapter(adapter);
}
SectionedAdapter adapter=new SectionedAdapter() {
protected View getHeaderView(String caption, int index,View convertView,ViewGroup parent) {
TextView result=(TextView)convertView;
if (convertView==null) {
result=(TextView)getLayoutInflater().inflate(R.layout.header, null);
}
result.setText(caption);
return(result);
}
};
}
其他的就需要你自己变化了,我这里只是吧内容打乱。
有些东西我只是简单调解没有源码或者我认为很简单的就不提供了。
对于复杂一些或者很难说清的 本人表达能力有限会把源码发上的
最新技术文章: