0
Я разрабатываю приложение для Android, в котором я хочу показывать фиды (изображения, видеофайлы, текст и профили picutres) в ListView ArrayAdapter. , когда загружается адаптер списка, тогда имя пользователя, изображение профиля (малый размер) и другой текст остаются со списком, в то время как большее изображение просматривается с прокруткой. Ниже мой моего адаптерИзображения в ArrayListAdapter получают dissappear с прокруткой вверх и вниз
public class Adapter_All_Feeds extends ArrayAdapter<String>
{
private Context context;
String mUrl;
ArrayList<String>feeds_id_lst=new ArrayList<String>();
ArrayList<String>feeds_email_lst=new ArrayList<String>();
ArrayList<String>feeds_name_lst=new ArrayList<String>();
ArrayList<String>feeds_path_lst=new ArrayList<String>();
ArrayList<String>feeds_profile_pic_path_lst=new ArrayList<String>();
ArrayList<String>feeds_description_lst=new ArrayList<String>();
ArrayList<String>feeds_date_lst=new ArrayList<String>();
ArrayList<String>feeds_time_lst=new ArrayList<String>();
SingletonClass obj=SingletonClass.getInstance();
int selected_pos=0;
static ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance
public Adapter_All_Feeds(Context context, int pos,
ArrayList<String> feeds_id_lst,
ArrayList<String> feeds_email_lst,
ArrayList<String> feeds_pic_path_lst,
ArrayList<String> feeds_profile_pic_path_lst,
ArrayList<String> feeds_description_lst,
ArrayList<String> feeds_date_lst,
ArrayList<String> feeds_time_lst,
ArrayList<String> feeds_name_lst
)
{
super(context, pos,feeds_email_lst);
this.context = context;
this.selected_pos=pos;
this.feeds_email_lst=feeds_email_lst;
this.feeds_id_lst=feeds_id_lst;
this.feeds_path_lst=feeds_pic_path_lst;
this.feeds_profile_pic_path_lst=feeds_profile_pic_path_lst;
this.feeds_description_lst=feeds_description_lst;
this.feeds_date_lst=feeds_date_lst;
this.feeds_time_lst=feeds_time_lst;
this.feeds_name_lst=feeds_name_lst;
}
static class ViewHolderItem
{
TextView textViewItem;
ImageView imgvw;
ImageView picIV;
TextView nameTV;
TextView datetimeTV;
TextView descriptionTV;
ImageView playIV;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView =convertView;
//rowView = inflater.inflate(R.layout.adapter_all_feeds, parent, false);
ViewHolderItem holder;
if(rowView==null)
{
// inflate the layout
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.adapter_all_feeds, parent, false);
holder = new ViewHolderItem();
holder.imgvw=(ImageView)rowView.findViewById(R.id.imageView1);
holder.picIV=(ImageView)rowView.findViewById(R.id.SquareImageView01);
holder.nameTV=(TextView)rowView.findViewById(R.id.textView1);
holder.datetimeTV=(TextView)rowView.findViewById(R.id.textView4);
holder.descriptionTV=(TextView)rowView.findViewById(R.id.textView2);
holder.playIV=(ImageView)rowView.findViewById(R.id.imageView3);
// store the holder with the view.
rowView.setTag(holder);
}
else
{
holder = (ViewHolderItem) convertView.getTag();
}
holder.nameTV.setText(""+feeds_name_lst.get(position));
// datetimeTV.setText(""+feeds_date_lst.get(position)+" at "+feeds_time_lst.get(position));
holder.descriptionTV.setText(""+feeds_description_lst.get(position));
String date=""+feeds_date_lst.get(position);
String[] parts = date.split("-");
int year1=2017,month1=1,day1=31;
String month_name = "Jan";
try
{
year1=Integer.parseInt(parts[0]);
month1=Integer.parseInt(parts[1]);
day1=Integer.parseInt(""+date.substring(date.lastIndexOf('-') + 1).trim());
month_name= ""+getMonthName(month1);
holder.datetimeTV.setText(""+month_name+" "+day1+" at "+feeds_time_lst.get(position));
}
catch(NumberFormatException o)
{
//showtoast("Error:"+o.getMessage());
}
if(feeds_profile_pic_path_lst.get(position).length()>5)
{
String url="http://pir.alphasols.com/Moody_Android_App/User_Profile_Pictures/"+feeds_profile_pic_path_lst.get(position);
setImagesUsingPicasso(url,holder.imgvw);
}
// else
// imgvw.setImageResource(R.drawable.add_photo_icon);
if(feeds_path_lst.get(position).length()>5)
{
String type=feeds_path_lst.get(position).substring(feeds_path_lst.get(position).length() - 3);
String url="http://pir.alphasols.com/Moody_Android_App/Phase_2_Php_Files/Feeds_n_WallFolder/"+feeds_path_lst.get(position);
if(type.equalsIgnoreCase("png"))
{
holder.playIV.setVisibility(View.GONE);
holder.picIV.setImageResource(0);
setImagesUsingPicasso(url,holder.picIV);
}
else
{
// url="http://pir.alphasols.com/Moody_Android_App/Phase_2_Php_Files/Feeds_n_WallFolder/[email protected]:57:38.mp4";
final String mUrl=""+url;
final ViewHolderItem holder2=holder;
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
Bitmap bitmap = null;
String videoPath = ""+mUrl;
MediaMetadataRetriever mediaMetadataRetriever = null;
try {
mediaMetadataRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
// no headers included
mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
else
mediaMetadataRetriever.setDataSource(videoPath);
// mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (mediaMetadataRetriever != null)
mediaMetadataRetriever.release();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if (bitmap != null)
{
holder2.playIV.setVisibility(View.VISIBLE);
holder2.picIV.setImageBitmap(bitmap);
}
}
}.execute();
}
}
return rowView;
}
public long getItemId(int position)
{
// return getItem(position).getContact().getId().hashCode();
return feeds_id_lst.get(position).length();
}
@Override
public boolean hasStableIds() {
return true;
}
//((((Retrive thaumnnail)))
public static Bitmap retriveVideoFrameFromVideo(String videoPath)
throws Throwable
{
Bitmap bitmap = null;
MediaMetadataRetriever mediaMetadataRetriever = null;
try
{
mediaMetadataRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
else
mediaMetadataRetriever.setDataSource(videoPath);
// mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime();
}
catch (Exception e)
{
e.printStackTrace();
throw new Throwable(
"Exception in retriveVideoFrameFromVideo(String videoPath)"
+ e.getMessage());
}
finally
{
if (mediaMetadataRetriever != null)
{
mediaMetadataRetriever.release();
}
}
return bitmap;
}
//(((Image Loading Using Picaso Library))))
private void setImagesUsingPicasso(final String URL,final ImageView imgVW)
{
String url=URL;
//Picasso.with(getApplicationContext()).load(url).fit().centerCrop().into(imgVW);
Picasso.with(context).load(url).into(new Target()
{
public void onBitmapLoaded (Bitmap bitmap, Picasso.LoadedFrom from)
{
// theView.setImageBitmap(bitmap);
//bitmap=getRoundedRectBitmap(bitmap, 100);
imgVW.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable arg0)
{
//Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.powered_by_google_dark);
//icon=getRoundedRectBitmap(icon, 100);
// imgVW.setImageBitmap(icon);
// setImagesUsingPicasso(URL,imgVW);
}
@Override
public void onPrepareLoad(Drawable arg0)
{
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.powered_by_google_dark);
//icon=getRoundedRectBitmap(icon, 100);
// imgVW.setImageBitmap(icon);
}
});
}
public static Bitmap getRoundedRectBitmap(Bitmap bitmap, int radius)
{
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
false);
else
finalBitmap = bitmap;
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
finalBitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawCircle(finalBitmap.getWidth()/2 + 0.7f,
finalBitmap.getHeight()/2 + 0.7f,
finalBitmap.getWidth()/2 + 0.1f, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, rect, paint);
return output;
}
private double distance(double lat1, double lon1, double lat2, double lon2) {
double theta = lon1 - lon2;
double dist = Math.sin(deg2rad(lat1))
* Math.sin(deg2rad(lat2))
+ Math.cos(deg2rad(lat1))
* Math.cos(deg2rad(lat2))
* Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
dist =Double.parseDouble(new DecimalFormat("##.#").format(dist));
return (dist);
}
private double deg2rad(double deg) {
return (deg * Math.PI/180.0);
}
private double rad2deg(double rad) {
return (rad * 180.0/Math.PI);
}
//(((Pass Int value and return month in string )))
public String getMonthName(int month)
{
String month_name="Jan";
switch(month)
{
case 1:
month_name="Jan";
break;
case 2:
month_name="Feb";
break;
case 3:
month_name="Mar";
break;
case 4:
month_name="Apr";
break;
case 5:
month_name="May";
break;
case 6:
month_name="Jun";
break;
case 7:
month_name="Jul";
break;
case 8:
month_name="Aug";
break;
case 9:
month_name="Sep";
break;
case 10:
month_name="Oct";
break;
case 11:
month_name="Nov";
break;
case 12:
month_name="Dec";
break;
}
return month_name;
}
public void showtoast(String str)
{
Toast.makeText(context, str, Toast.LENGTH_LONG).show();
}
} //EOF Class
На самом деле я занимаюсь разработкой приложения, как каналы facebook, порог профиль с небольшим размером, именем, датой и описанием приведены и ниже этого показаны большие изображения, поэтому все остальные (профиль пользователя, имя, дата и т. д.) не меняются с помощью scoll, только изменение большого изображения происходит с помощью прокрутки вверх и вниз. –
Что такое getCount и позиция –
просто добавьте два метода в свой адаптер, это поможет вам убедиться, что теперь –