In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to solve the jump caused by ListView picture download optimization", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the jump caused by the optimization of ListView picture download.
Public class MainActivity extends Activity {
HashMap map = new 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 ()
}
/ / download pictures
/ / set the status of the image before it starts downloading
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 ("http://192.168.56.1:8080/service/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 paired 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) {
/ / get the first line visible on the current screen
Int fvb = listview.getFirstVisiblePosition ()
Int lvp = listview.getLastVisiblePosition ()
If (position > = fvb&&position
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.