convertView = inflater.inflate (R.layout. listview_layout, null); ImageView imageView = convertView.findViewById(R.id.imageView); TextView serialTextView = convertView.findViewById(R.id.textView1); TextView nameTextView = convertView.findViewById(R.id.textView2); TextView scoreTextView convertView.findViewById(R.id.textViews); imageView.setImageResource (flags [position]); serialTextView.setText (serialNo [position]); nameTextView.setText (names [position]); scoreTextView.setText (scores [position]); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bitmap bitmap = BitmapFactory.decodeResource (context.getResources (), flags [position]); try { // Get the directory for the app's private pictures directory. File file = new File(context.getExternalFiles Dir(s: null), names [position] + ".jpg"); FileOutputStream fos = new FileOutputStream(file); bitmap.compress (Bitmap.CompressFormat.JPEG, 90, fos); fos.close(); Toast.makeText(context, "Image saved successfully", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, "Error saving image", Toast.LENGTH_SHORT).show();

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

customeradaper class is like this 

package com.example.myapplication;
import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.zip.Inflater;
public class CustomAdapter extends BaseAdapter {
Context context;
ListView listView;
String[] serialNo;
int[] flags;
String[] names;
String[] scores;

public CustomAdapter(Context applicationContext, ListView simpleList, String[] serialNo, int[] flags, String[] names, String[] score) {
this.context = applicationContext;
this.listView = simpleList;
this.serialNo = serialNo;
this.flags = flags;
this.names = names;
this.scores = score;
}

@Override
public int getCount() {
return flags.length;
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.listview_layout, null);

ImageView imageView = convertView.findViewById(R.id.imageView);
TextView serialTextView = convertView.findViewById(R.id.textView1);
TextView nameTextView = convertView.findViewById(R.id.textView2);
TextView scoreTextView = convertView.findViewById(R.id.textView3);

imageView.setImageResource(flags[position]);
serialTextView.setText(serialNo[position]);
nameTextView.setText(names[position]);
scoreTextView.setText(scores[position]);

imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), flags[position]);

try {
// Get the directory for the app's private pictures directory.
File file = new File(context.getExternalFilesDir(null), names[position] + ".jpg");
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
Toast.makeText(context, "Image saved successfully", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "Error saving image", Toast.LENGTH_SHORT).show();
}
}
});

return convertView;
}
}

---------------------------------------

there are some errors in this code ,whats wrong with  these red parts and how to fix them .

 

convertView = inflater.inflate (R.layout.listview_layout, null);
ImageView imageView = convertView.findViewById(R.id.imageView);
TextView serialTextView = convertView.findViewById(R.id.textView1);
TextView nameTextView = convertView.findViewById(R.id.textView2);
TextView scoreTextView = convertView. findViewById(R.id.textView3);
imageView.setImageResource
(flags [position]);
serialTextView.setText (serialNo [position]);
nameTextView.setText (names [position]);
scoreTextView.setText (scores [position]);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = BitmapFactory.decodeResource (context.getResources (), flags [position]);
}
try {
// Get the directory for the app's private pictures directory.
File file = new File(context.getExternalFilesDir(s: null), names [position] + .jpg");
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress (Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
Toast.makeText(context, "Image saved successfully", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "Error saving image", Toast.LENGTH_SHORT).show();
}
Transcribed Image Text:convertView = inflater.inflate (R.layout.listview_layout, null); ImageView imageView = convertView.findViewById(R.id.imageView); TextView serialTextView = convertView.findViewById(R.id.textView1); TextView nameTextView = convertView.findViewById(R.id.textView2); TextView scoreTextView = convertView. findViewById(R.id.textView3); imageView.setImageResource (flags [position]); serialTextView.setText (serialNo [position]); nameTextView.setText (names [position]); scoreTextView.setText (scores [position]); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bitmap bitmap = BitmapFactory.decodeResource (context.getResources (), flags [position]); } try { // Get the directory for the app's private pictures directory. File file = new File(context.getExternalFilesDir(s: null), names [position] + .jpg"); FileOutputStream fos = new FileOutputStream(file); bitmap.compress (Bitmap.CompressFormat.JPEG, 90, fos); fos.close(); Toast.makeText(context, "Image saved successfully", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, "Error saving image", Toast.LENGTH_SHORT).show(); }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Image Element
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education