Why ImageView Not appear image in my app? - java

i saved photo in server and show it in another place in my app but image doesn't appear in imageview and when i make log.e for url of image url was correct so i don't know why image not appear in imageview any help ????
public CustListMis(Activity context, ArrayList<String> NameArray, ArrayList<String> quantityArray, ArrayList<String> durationArray, ArrayList<String> dTimeArray, ArrayList<String> Images) {
super(context, R.layout.temp_mis, quantityArray);
this.context = context;
this.NameArray = NameArray;
this.quantityArray = quantityArray;
this.durationArray = durationArray;
this.dTimeArray= dTimeArray;
this.Images = Images;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.temp_mis, null, true);
TextView name = (TextView) listViewItem.findViewById(R.id.name);
TextView quantity = (TextView) listViewItem.findViewById(R.id.quantity);
TextView duration = (TextView) listViewItem.findViewById(R.id.duration);
TextView dTime = (TextView) listViewItem.findViewById(R.id.dTime);
ImageView myUploadImage = (ImageView)listViewItem.findViewById(R.id.imageyy);
String url = Images.get(position);
// String url = "http://sae-marketing.com/gamaia/PHOTOS/dream.age25#gmail.com-554806.png";
Log.e("image",url);
Picasso.with(context).load(url).noFade().resize(50, 50).centerCrop().into(myUploadImage);
name.setText(NameArray.get(position));
quantity.setText(quantityArray.get(position));
duration.setText(durationArray.get(position));
dTime.setText(dTimeArray.get(position));
return listViewItem;
}

Following OP comments we eventually ended up that the problem was really in the String url variable that does not contains a valid URL string (missing http://).
So the solution ended in doing that:
//String url = "http://sae-marketing.com/gamaia/PHOTOS/dream.age25#gmail.com-554806.png";
String url = "http://" + Images.get(position);
ImageView iv = findViewById(R.id.imageView);
Picasso.with(this).load(url).into(iv);

ou can turn on Picasso logs using
Picasso.with(Context).setLoggingEnabled(true)
You will probably see an error message with a reason there

Related

Recyclerview is lagging to much

Here is my code
this is my recyclerview adapter code ..
i dnot konw why my recycler view lagging after schroll
Pleas Help ME
public class Recyclerview1Adapter extends RecyclerView.Adapter<Recyclerview1Adapter.ViewHolder> {
ArrayList<HashMap<String, Object>> _data;
public Recyclerview1Adapter(ArrayList<HashMap<String, Object>> _arr) {
_data = _arr;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater _inflater = getActivity().getLayoutInflater();
View _v = _inflater.inflate(R.layout.video_item, null);
RecyclerView.LayoutParams _lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
_v.setLayoutParams(_lp);
return new ViewHolder(_v);
}
#Override
public void onBindViewHolder(ViewHolder _holder, final int _position) {
View _view = _holder.itemView;
final LinearLayout linear1 = _view.findViewById(R.id.linear1);
final LinearLayout linear2 = _view.findViewById(R.id.linear2);
final LinearLayout linear4 = _view.findViewById(R.id.linear4);
final androidx.cardview.widget.CardView cardview2 = _view.findViewById(R.id.cardview2);
final LinearLayout linear3 = _view.findViewById(R.id.linear3);
final LinearLayout linear7 = _view.findViewById(R.id.linear7);
final ImageView imageview1 = _view.findViewById(R.id.imageview1);
final TextView textview1 = _view.findViewById(R.id.textview1);
final TextView textview2 = _view.findViewById(R.id.textview2);
final LinearLayout linear5 = _view.findViewById(R.id.linear5);
final TextView textview3 = _view.findViewById(R.id.textview3);
final TextView textview4 = _view.findViewById(R.id.textview4);
final LinearLayout linear10 = _view.findViewById(R.id.linear10);
final ImageView imageview3 = _view.findViewById(R.id.imageview3);
_shapeRadius(textview1, "#000000", 6);
_shapeRadius(textview4, "#272731", 8);
textview1.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"fonts/spartan_regular.ttf"), 0);
textview2.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"fonts/spartan_bold.ttf"), 0);
textview3.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"fonts/spartan_regular.ttf"), 0);
textview4.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"fonts/spartan_bold.ttf"), 0);
textview1.setTextSize((int)8);
cardview2.setBackground(new GradientDrawable() { public GradientDrawable getIns(int a, int b) { this.setCornerRadius(a); this.setColor(b); return this; } }.getIns((int)18, 0xFF272731));
duration = Double.parseDouble(allVideosList.get((int)_position).get("videoDuration").toString());
videoDuration = stringForTime((int)duration);
textview1.setText(videoDuration);
path = allVideosList.get((int)_position).get("videoPath").toString();
//using cardview programmatically inside listview is not good. use recyclerview instead of listview.
androidx.cardview.widget.CardView cardview1 = new androidx.cardview.widget.CardView(VideoListFragmentActivity.this.getContext());
cardview1.setCardElevation(0);
cardview1.setCardBackgroundColor(0xFF272731);
cardview1.setRadius(18);
ViewGroup imageParent = ((ViewGroup)imageview1.getParent()); imageParent.removeView(imageview1);
cardview1.addView(imageview1);
imageParent.addView(cardview1);
textview2.setText(Uri.parse(path).getLastPathSegment());
size = Double.parseDouble(allVideosList.get((int)_position).get("videoSize").toString());
humanReadableSize = bytesIntoHumanReadable((long)size);
textview3.setText(allVideosList.get((int)_position).get("formattedDate").toString());
com.bumptech.glide.Glide.with(getContext().getApplicationContext())
.load(path)
.transition(DrawableTransitionOptions.withCrossFade(factory))
.placeholder(R.drawable.video_background)
.error(R.drawable.video_background)
.fitCenter()
.into(imageview1);
textview4.setText(humanReadableSize);
}
#Override
public int getItemCount() {
return _data.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View v) {
super(v);
}
}
}
Iam trying to create a video player app after adding rcyclerview with glide image loader library , recyclerview is lagging after scroll , get all videos from storage using mediastore then add in a list and add list in recyclerview , but after load more than 100 videos recycler view is lagging to much so please help me .
I think you should try moving stuff from onBindViewHolder to onCreateViewHolder, such as all the setTypeface calls. You shouldn't be calling those every time you bind.
Do you need to create those typefaces for every textview in every viewholder? Maybe you could load those once somewhere else, like in the constructor.
Why are you finding all those linearLayouts in onBindViewHolder? They don't seem to be used in the code.
Ultimately, though, I think most of your latency is probably coming from the
com.bumptech.glide.Glide component, which looks like you are loading a video for each item. You could try creating a test loop that all it does is load all those videos using this component, and time how long it takes.

How can I pass a ListView contaning imageView and textView to other Activity

I have 2 different activities but both of them has a listview. My first activity is empty in terms of data. It just has a button for passing to my second activity.
Each row contains one imageView, textView and checkBox in my second activity.
When I make the checkbox active in my second activity any row, I want to send data to my first activity. For example, I click a checkbox for selecting a line, and when I back in first activity, I should see this line (with ImageView, TextView). Actually, in addition, I want to delete data in first activity when checkbox isn't active. However, I am thinking that I can find this solution if you help me for my first question.
MY FIRST ACTIVITY (I should see rows in here)
ImageView image = (ImageView) findViewById(R.id.image);
Bundle bundleObject = getIntent().getExtras();
if (bundleObject != null) {
String resultText = bundleObject.getString("RESULT_TEXT");
dbHelper.insertNewTask(resultText);
byte[] byteArray = bundleObject.getByteArray("picture");
Bitmap b = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
image.setImageBitmap(b); //ERROR IS HERE!!!!! IT ISN'T WORKING
MY SECOND ACTIVITY
byte[] byteArray;
Bitmap bmp;
int[] images = {R.drawable.book, R.drawable.watchingtv};
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.book);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
class MyAdapter extends ArrayAdapter<String> implements View.OnClickListener {
Context context;
int[] images;
String[] mytitles;
MyAdapter(Context c, String[] titles, int images[]) {
super(c, R.layout.row_2, R.id.newTaskTitle, titles);
this.context = c;
this.images = images;
this.mytitles = titles;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.row_2, parent, false);
ImageView myImage = (ImageView) row.findViewById(R.id.newImage);
final TextView myTitle = (TextView) row.findViewById(R.id.newTaskTitle);
myImage.setImageResource(images[position]);
myTitle.setText(mytitles[position]);
checkBox = (CheckBox) row.findViewById(R.id.checkBox);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Boolean durum = checkBox.isChecked();
if(durum=true){
Intent intent = new Intent (dinlenmeEkrani_newOptions.this, dinlenmeEkrani.class);
intent.putExtra("picture", byteArray);
intent.putExtra("RESULT_TEXT", myTitle.getText().toString());
startActivity(intent);
}
else{
}
}
});
return row;
}
Second activity might has mistakes. When I try to reach the solution, I might do some mistakes.
I want to say these : I have succeeded in terms of passing textview. So, When I delete some codes related to Image (especially in my first activity), I see passing textView which is coming from String.xml. And also, I just have tried R.Drawable.book because if it works, I think that I can add others drawables.
(if you wonder dbHelper, it is here)
public class Database extends SQLiteOpenHelper
public static final String DB_TABLE = "Task";
public static final String DB_COLUMN = "TaskName";
public void insertNewTask (String task){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DB_COLUMN,task);
db.insertWithOnConflict(DB_TABLE,null,values, SQLiteDatabase.CONFLICT_REPLACE);
db.close();
}
Isn't possible to share any view object between activities, because their are linked with the Activity and Activities are completely independent. You need to create a logic to identify and deal with states just passing small pieces of data between activities, like you are already doing with the intent.

Android Picasso does not load all image to imageview

I am trying to load images to imageview in my ListAdapter. However while I am passing 10 thumbnail images to listAdapter and set them in imageview, only 1 or none is visible in imageview. As I understand from docs, I dont need to use any asyntask, since picasso library has already working asyntask. Could you please help me how I can handle this issue?
// Calling CustumListAdapter like this;
CustomListAdapter customListAdapter = new CustomListAdapter(this, resultArrayList);
listView = (ListView) findViewById(R.id.listview_score);
listView.setAdapter(customListAdapter)
// And here is my CustomListAdapter class
public class CustomListAdapter extends ArrayAdapter<String> {
private ArrayList<String> resultContent;
//private Integer[] imageid;
private Activity context;
public CustomListAdapter(Activity context, ArrayList<String> resultContent) {
super(context, R.layout.activity_ident_result2, resultContent);
this.context = context;
this.resultContent = resultContent;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.activity_ident_result2, null, true);
if (position % 2 == 0) {
TextView textViewName = (TextView) listViewItem.findViewById(R.id.textView_score);
textViewName.setText(resultContent.get(position));
ImageView imageView = (ImageView) listViewItem.findViewById(R.id.imageView_score);
//imageView.setImageBitmap(IdentResultActivity.splittedBitmaps.get(position + 1));
Picasso.with(this.context).load(resultContent.get(position + 1)).into(imageView);
}
return listViewItem;
}
}
EDIT:
I used .placeholder(R.drawble.progress) and I can see one image placed without problem, rest are progress.png
EDIT2:
Here is my imageView xml file;
<ImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:id="#+id/imageView_score" />
I believe the parameters of inflater.inflate should be (R.layout.activity_ident_result2, parent, false)
U need to create loop for adding every image to [] and then u need to show it. Becouse of ur posted code u adding just one image.

GridView Performance lag with Custom CursorAdapters

I'm currently trying to get the hang of android developemnt and so far its been going good(Well until now). I am currently playing around with Custom Cursor adapters for my grid view. I read using a cursor adapter takes the load of the main UI thread which sounds efficient, so i tried to implement my own cursor adapter as follows
public class VideoListAdapter extends SimpleCursorAdapter{
private Context ctx;
private int parent_layout_id;
ArrayList<VideoModel> videoList = new ArrayList<VideoModel>();
public VideoListAdapter(
Context ctx,
int parent_layout_id,
Cursor c,
String[] fromColumns,
int[] toView)
{
super(ctx,parent_layout_id,c,fromColumns,toView);
this.ctx = ctx;
this.parent_layout_id = parent_layout_id;
}
#Override
public void bindView(View v, Context context, Cursor c) {
//gets title column
int titleColumn = c.getColumnIndex(MediaStore.Video.Media.TITLE);
String title = c.getString(titleColumn);
TextView titleView =(TextView) v.findViewById(R.id.video_title);
titleView.setText(title);
//gets duration
int durationColumn = c.getColumnIndex(MediaStore.Video.Media.DURATION);
String duration = c.getString(durationColumn);
TextView durationView = (TextView) v.findViewById(R.id.video_date);
durationView.setText(duration);
//gets Thumb
int videoDataColumn = c.getColumnIndex(MediaStore.Video.Media.DATA);
String videodataUrl = c.getString(videoDataColumn);
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(videodataUrl);
Bitmap bm = mmr.getFrameAtTime(1000);
ImageView imgv = (ImageView) v.findViewById(R.id.video_thumb);
imgv.setScaleType(ImageView.ScaleType.CENTER_CROP);
imgv.setImageBitmap(bm);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Cursor c = getCursor();
//get layout inflater
final LayoutInflater li=LayoutInflater.from(context);
View v = li.inflate(parent_layout_id,parent,false);
//gets title column
int titleColumn = c.getColumnIndex(MediaStore.Video.Media.TITLE);
String title = c.getString(titleColumn);
TextView titleView =(TextView) v.findViewById(R.id.video_title);
titleView.setText(title);
//gets duration
int durationColumn = c.getColumnIndex(MediaStore.Video.Media.DURATION);
String duration = c.getString(durationColumn);
TextView durationView = (TextView) v.findViewById(R.id.video_date);
durationView.setText(duration);
//gets Thumb
int videoDataColumn = c.getColumnIndex(MediaStore.Video.Media.DATA);
String videodataUrl = c.getString(videoDataColumn);
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(videodataUrl);
Bitmap bm = mmr.getFrameAtTime(1000);
ImageView imgv = (ImageView) v.findViewById(R.id.video_thumb);
imgv.setScaleType(ImageView.ScaleType.CENTER_CROP);
imgv.setImageBitmap(bm);
return v;
}
#Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
return super.runQueryOnBackgroundThread(constraint);
}
}
What i'm trying to achieve is to fetch list of video files from the external media storage and display them in a gridview. the standard thumbnails are abit too small for the style of layout i have in mind so i used the MediaMetadataRetriever to fetch frames from each of the video files and used that as thumbnails. Like so
When i ran the application the scroll performance of my gridView worsened. What am I missing. i know the SimpleCursorAdapter class has an overridable method runQueryOnBackgroundThread but i dont even know what to put in there or how to use it. Any pointers will be very much appreciated and forgive my smudge face ;)
First of all bind your Gridview using ViewHolder and second one is save your thumb(bitmap) in existing arrayList so you can not do have to same process while scrolling.

Change String Array to List<String> - Java/Android

I am updating a custom adapter and had to change the value from a String Array to a List.
Here is code:
private final List<String> values;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.comments_listadapter, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.comments_label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.comments_menu);
textView.setText(values[position]); // Needs to Change!
String s = values[position]; // Needs to Change!
imageView.setImageResource(R.drawable.up_down);
return rowView;
}
I have marked the two lines that need to change (I am not sure if changing it to a List will need more to change?
List<String> mStringList = Arrays.asList(values);
where values is a string array.
Arrays class is in java.util package.
If I understand your question correctly, you're looking for:
String s = values.get(position);
textView.setText(s);
Try this
String s = getItem(position);
textView.setText(s);
So it sounds like you have something like String[] values which you want to be List<String> values.
Here is how you can do the conversion:
List<String> listValues = new ArrayList<String>();
for(String s : values) {
listValues.add(s);
}
Then instead of values[position], you do listValues.get(position).
What exactly is your problem?
Do you mean you have to change your references to
mList.get(position);
mList.add(position, string);

Categories