package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import java.io.File; import java.io.FileOutputStream; public class PlayerActivity2 extends AppCompatActivity { ListView simpleList; String SerialNo[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; int flags[] = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6, R.drawable.image7, R.drawable.image8, R.drawable.image9, R.drawable.image10}; String Names[] = {"mmm", "nnn", "aaa.", "bbb", "ccc", "ddd", "eee jk", " ijk", "Virgil jk", "gil jklk"}; String Score[] = {"1", "2", "3", "5", "4", "3", "5", "5", "5", "5"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity2); simpleList = findViewById(R.id.simpleListView); CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), simpleList, SerialNo, flags, Names, Score); simpleList.setAdapter(customAdapter); simpleList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int position, long id) { ImageView imageView = view.findViewById(R.id.imageView); if (imageView != null) { saveImage(imageView, Names[position]); } } }); } public void saveImage(View view, String name) { ImageView imageView = (ImageView) view; Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); String fileName = name + ".jpg"; File dir = getApplicationContext().getDir("images", Context.MODE_PRIVATE); File file = new File(dir, fileName); try { FileOutputStream fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); Toast.makeText(getApplicationContext(), "Image saved", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } public void showToast(View view) { Toast.makeText(getApplicationContext(), "Save Image button clicked", Toast.LENGTH_SHORT).show(); } } whats wrong with this code ,it always show bug on this part [imageview ]
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import java.io.File;
import java.io.FileOutputStream;
public class PlayerActivity2 extends AppCompatActivity {
ListView simpleList;
String SerialNo[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
int flags[] = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6, R.drawable.image7, R.drawable.image8, R.drawable.image9, R.drawable.image10};
String Names[] = {"mmm", "nnn", "aaa.", "bbb", "ccc", "ddd", "eee jk", " ijk", "Virgil jk", "gil jklk"};
String Score[] = {"1", "2", "3", "5", "4", "3", "5", "5", "5", "5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
simpleList = findViewById(R.id.simpleListView);
CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), simpleList, SerialNo, flags, Names, Score);
simpleList.setAdapter(customAdapter);
simpleList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
ImageView imageView = view.findViewById(R.id.imageView);
if (imageView != null) {
saveImage(imageView, Names[position]);
}
}
});
}
public void saveImage(View view, String name) {
ImageView imageView = (ImageView) view;
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
String fileName = name + ".jpg";
File dir = getApplicationContext().getDir("images", Context.MODE_PRIVATE);
File file = new File(dir, fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
Toast.makeText(getApplicationContext(), "Image saved", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
public void showToast(View view) {
Toast.makeText(getApplicationContext(), "Save Image button clicked", Toast.LENGTH_SHORT).show();
}
}
whats wrong with this code ,it always show bug on this part [imageview ]
![m
→
A
@
B
B
Coll
}
CustomAdapter customAdapter = new CustomAdapter (getApplicationContext(),
simpleList.set Adapter (customAdapter);
simpleList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> adapterView, View view, int po:
view. findViewById(R.id.imageView);
ImageView imageView
if (imageView != null) {
ec, 229 ms
ndroid Gri
ec, 111 ms
});
}
}
save Image (imageView, Names [position]);
1 usage
public void save Image (View view, String name) {
ImageView imageView (ImageView) view;
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
=
String fileName = name + ".jpg";
File dir = getApplicationContext().getDir(s: "images", Context.MODE_PRIVA
File file = new File(dir, fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress (Bitmap. CompressFormat.JPEG, quality: 100, fos);
V:\eic\kkkk\MyApplication\app\src\main\java\com\example.myapplication Playe
ImageView imageView = view. findViewById(R.id.imageView);
id
imageView](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd7770d6e-352d-49c5-bb02-13e122a27c4b%2F150338eb-f66d-4368-b4d4-e4d158713462%2Fy8h2unr_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)