真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

androidlistView性能優(yōu)化

package com.example.ex_000_example;

專注于為中小企業(yè)提供成都做網(wǎng)站、網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)喀喇沁免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

import java.util.ArrayList;

import android.os.Bundle;

import android.app.Activity;

import android.util.Log;

import android.view.LayoutInflater;

import android.view.Menu;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

import android.widget.BaseAdapter;

import android.widget.ImageView;

import android.widget.ListView;

import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

        //準(zhǔn)備好的圖片資源

private int[] p_w_picpathList = new int[] { R.drawable.qq0, R.drawable.qq1,

R.drawable.qq2, R.drawable.qq3, R.drawable.qq4, R.drawable.qq5,

R.drawable.qq6, R.drawable.qq7, R.drawable.qq8, R.drawable.qq9,

R.drawable.qq10, R.drawable.qq11, R.drawable.qq12, R.drawable.qq13,

R.drawable.qq14 };

private ArrayList dateList = new ArrayList();

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// 準(zhǔn)備數(shù)據(jù)

for (int i = 0; i < p_w_picpathList.length; i++) {

MyDate myDate = new MyDate("數(shù)據(jù)來了"+i, p_w_picpathList[i]);

dateList.add(myDate);

}

ListView listView = (ListView) findViewById(R.id.listView1);

MyAdapter myAdapter = new MyAdapter();

// 設(shè)置適配器

listView.setAdapter(myAdapter);

}

        //減少控件查找次數(shù)

class ViewHolder {

TextView textView;

ImageView p_w_picpathView;

}

class MyAdapter extends BaseAdapter {

// 設(shè)定每行的樣式以及顯示

@Override

public View getView(int position, View convertView, ViewGroup parent) {

View inflate = null;

ViewHolder holder = null;

if (convertView == null) {

holder = new ViewHolder();

// 得到布局轉(zhuǎn)換器

LayoutInflater inflater = getLayoutInflater();

// 將布局xml文件轉(zhuǎn)換成布局對(duì)象

inflate = inflater.inflate(R.layout.list_item, null);

// 查找控件,一定要查找該布局對(duì)象上有的控件

holder.textView = (TextView) inflate

.findViewById(R.id.textView1);

holder.p_w_picpathView = (ImageView) inflate

.findViewById(R.id.p_w_picpathView1);

// 將保存控件的對(duì)象存入行布局對(duì)象的tag中

inflate.setTag(holder);

} else {

// 讓那個(gè)已經(jīng)完全消失的布局對(duì)象,去替代即將出現(xiàn)的

inflate = convertView;

// 從行布局對(duì)象中取出之前存好的控件

holder = (ViewHolder) inflate.getTag();

}

// 根據(jù)position從容器中取出數(shù)據(jù)

MyDate myDate = dateList.get(position);

// 將數(shù)據(jù)顯示到控件上

holder.textView.setText(myDate.title);

holder.p_w_picpathView.setImageResource(myDate.p_w_picpath);

return inflate;

}

// 決定了listview顯示的行數(shù)

@Override

public int getCount() {

// TODO Auto-generated method stub

return dateList.size();

}

@Override

public Object getItem(int position) {

// TODO Auto-generated method stub

return null;

}

@Override

public long getItemId(int position) {

// TODO Auto-generated method stub

return 0;

}

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

    class MyDate{

String title;

int p_w_picpath;

public MyDate(String title, int p_w_picpath) {

super();

this.title = title;

this.p_w_picpath = p_w_picpath;

}

}

}


分享文章:androidlistView性能優(yōu)化
分享網(wǎng)址:http://weahome.cn/article/pdeddc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部