本篇內(nèi)容主要講解“ListView圖片下載優(yōu)化造成的跳變?cè)趺唇鉀Q”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“ListView圖片下載優(yōu)化造成的跳變?cè)趺唇鉀Q”吧!
安遠(yuǎn)網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)于2013年創(chuàng)立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。public class MainActivity extends Activity {
HashMap
private ListView listview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView)findViewById(R.id.listView1);
MyApapter myApapter = new MyApapter();
listview.setAdapter(myApapter);
}
class User
{
ImageView p_w_picpathview;
ProgressBar pb;
TextView tv;
Button button;
}
class MyApapter extends BaseAdapter
{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
User user = new User();
LayoutInflater inflater = getLayoutInflater();
if(convertView==null)
{
view = inflater.inflate(R.layout.itmp, null);
user.p_w_picpathview = (ImageView)view.findViewById(R.id.p_w_picpathView1);
user.pb = (ProgressBar)view.findViewById(R.id.progressBar1);
user.button = (Button)view.findViewById(R.id.button1);
user.tv = (TextView)view.findViewById(R.id.textView1);
view.setTag(user);
}else
{
view = convertView;
user = (User)view.getTag();
}
//下載圖片
//設(shè)置圖片還未開(kāi)始下載時(shí)的狀態(tài)
user.p_w_picpathview.setImageResource(R.drawable.ic_launcher);
Bitmap bitmap = map.get(position);
if (bitmap==null)
{
MyAsyncTask myp_w_picpathview = new MyAsyncTask(user.p_w_picpathview,position,user.pb);
myp_w_picpathview.execute("/upload/otherpic14/qq"+position+".png");
}else
{
user.p_w_picpathview.setImageBitmap(bitmap);
}
return view;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 10;
}
@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;
}
}
class MyAsyncTask extends AsyncTask
{
int position;
ImageView p_w_picpathview;
ProgressBar pb;
public MyAsyncTask(ImageView p_w_picpathview,int position,ProgressBar pb) {
this.p_w_picpathview = p_w_picpathview;
this.position = position;
this.pb = pb;
}
@Override
protected Bitmap doInBackground(String... params) {
Bitmap bitmap = null;
try {
URL url = new URL(params[0]);
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
//得到當(dāng)前屏幕可見(jiàn)第一行
int fvb = listview.getFirstVisiblePosition();
int lvp = listview.getLastVisiblePosition();
if (position>=fvb&&position<=lvp)
{
p_w_picpathview.setImageBitmap(result);
}
map.put(position, result);
super.onPostExecute(result);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
到此,相信大家對(duì)“ListView圖片下載優(yōu)化造成的跳變?cè)趺唇鉀Q”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。