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();

New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter7: Designing A Web Form: Creating A Survey Form
Section: Chapter Questions
Problem 4CP3
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
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L