Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7407733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:46:37+00:00 2026-05-29T05:46:37+00:00

I have listAdapter of listview and I have set record button in custom adapter.

  • 0

I have listAdapter of listview and I have set record button in custom adapter. I have put code inside click event of holder.record like

holder.record.setBackgroundResource(R.drawable.record_green); 

for set background of that button while user touch.but my problem is when I touch particular list item button this images are apply in another list item

Here are code:

holder.record.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {

        if (isplaying2 == true) {

        } else
        { 
            if (b_Flag_Record_or_not == true) {
            } else {
                try {

                    holder.record.setBackgroundResource(R.drawable.record_green);
                    b_Flag_Record_or_not = true;
                    b_play_or_not = true;

                    flag_stop_position = position;
                    AuthHandler dataHandler = new AuthHandler();
                    AuthDataset dataset = dataHandler
                            .getParsednewJobdtl_DataSet();

                    System.out.println("dataset.getint1();"
                            + dataset.getint1());
                    // Login l = new Login();
                    String str_useid = RequestTo[position];
                    recorder = new AudioRecorder("/audiometer/shanesh"
                            + RequestId[position] + "-" + str_useid);
                    start_or_not = true;
                    recorder.start();
                    Toast.makeText(context, "Start Recording", Toast.LENGTH_LONG).show();
                    CountDownTimer countDowntimer = new CountDownTimer(
                            120000000, 1000) {
                        public void onTick(long millisUntilFinished) {
                        }

                        public void onFinish() {
                            try {
                                Toast.makeText(
                                        context,
                                        "Stop recording Automatically ",
                                        Toast.LENGTH_LONG).show();
                                recorder.stop();
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    };
                    countDowntimer.start();

                } catch (IOException e) {
                    Writer writer = new StringWriter();
                    PrintWriter printWriter = new PrintWriter(writer);
                    e.printStackTrace(printWriter);
                    String s = writer.toString();

                }catch (Exception e) {

                }
            }

        }
    }
});

Update:

public class ListViewAdapter extends BaseAdapter {

public static Activity context;

String title[];
String description[];
String RequestId[];
String Folderpath[];
String RequestTo[];

boolean b_Flag_Record_or_not = false;
boolean b_upload_or_not = false;
boolean start_or_not = false;
boolean start_play = false;
boolean upload_or_not = false;
boolean b_play_or_not = false;
boolean isplaying2 = false;

Thread welcomeThread;
int glob_position;
MediaPlayer mPlayer2;
int flag_stop_position;
AudioRecorder recorder;
AnimationDrawable frameAnimation, frameAnimation_play;
private static String mFileName = null;
private MediaRecorder mRecorder = null;
private MediaPlayer mPlayer = null;
Recording login = new Recording();
ViewHolder holder;
MediaPlayer MP_completeRequest = new MediaPlayer();

public ListViewAdapter(Activity context, String[] title,
        String[] description, String[] req_id, String[] FolderPath,
        String[] Arr_RequestTo) {
    super();
    this.context = context;
    this.title = title;
    this.description = description;
    this.RequestId = req_id;
    this.Folderpath = FolderPath;
    this.RequestTo = Arr_RequestTo;
}

public int getCount() {
    // TODO Auto-generated method stub
    return title.length;
}

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

private class ViewHolder {
    TextView txtViewTitle;
    TextView txtViewDescription;
    Button record, stop, play, upload;
}

public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    LayoutInflater inflater = context.getLayoutInflater();
    glob_position = position;
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.listitem_row, null);
        holder = new ViewHolder();
        holder.txtViewTitle = (TextView) convertView
                .findViewById(R.id.textView1);
        holder.txtViewDescription = (TextView) convertView
                .findViewById(R.id.textView2);
        holder.record = (Button) convertView.findViewById(R.id.record);

        holder.stop = (Button) convertView.findViewById(R.id.stop);
        holder.play = (Button) convertView.findViewById(R.id.play1);
        holder.upload = (Button) convertView
                .findViewById(R.id.audio_upload);
        /* set button image */



        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    try {

        Typeface face = Typeface.createFromAsset(context.getAssets(),
                "fonts/tahoma.ttf");
        holder.txtViewTitle.setTypeface(face);

        holder.txtViewTitle.setText(title[position]);
        holder.txtViewDescription.setText(description[position]);


    } catch (ArrayIndexOutOfBoundsException e) {
        e.printStackTrace();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:46:38+00:00Added an answer on May 29, 2026 at 5:46 am

    Please see Holder is used to reuse views in adapterview, so if a Screen can displays 5 items once, 6th item will reuse item no 1’s View, hence holder.

    Use ListView.onItemClickListener instead of holder.record.setOnClickListener(), or set background of view into getView method, I am editing your code in getVIew method:

        public class ListViewAdapter extends BaseAdapter {
    
    public static Activity context;
    
    String title[];
    String description[];
    String RequestId[];
    String Folderpath[];
    String RequestTo[];
    
    boolean b_Flag_Record_or_not = false;
    boolean b_upload_or_not = false;
    boolean start_or_not = false;
    boolean start_play = false;
    boolean upload_or_not = false;
    boolean b_play_or_not = false;
    boolean isplaying2 = false;
    
    Thread welcomeThread;
    int glob_position;
    MediaPlayer mPlayer2;
    int flag_stop_position;
    AudioRecorder recorder;
    AnimationDrawable frameAnimation, frameAnimation_play;
    private static String mFileName = null;
    private MediaRecorder mRecorder = null;
    private MediaPlayer mPlayer = null;
    Recording login = new Recording();
    ViewHolder holder;
    MediaPlayer MP_completeRequest = new MediaPlayer();
    
    public ListViewAdapter(Activity context, String[] title,
            String[] description, String[] req_id, String[] FolderPath,
            String[] Arr_RequestTo) {
        super();
        this.context = context;
        this.title = title;
        this.description = description;
        this.RequestId = req_id;
        this.Folderpath = FolderPath;
        this.RequestTo = Arr_RequestTo;
    }
    
    public int getCount() {
        // TODO Auto-generated method stub
        return title.length;
    }
    
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }
    
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }
    
    private class ViewHolder {
        TextView txtViewTitle;
        TextView txtViewDescription;
    }
    
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
    
        LayoutInflater inflater = context.getLayoutInflater();
        glob_position = position;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listitem_row, null);
            holder = new ViewHolder();
            holder.txtViewTitle = (TextView) convertView
                    .findViewById(R.id.textView1);
            holder.txtViewDescription = (TextView) convertView
                    .findViewById(R.id.textView2);
    
            /* set button image */
    
    
    
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        try {
    
            Typeface face = Typeface.createFromAsset(context.getAssets(),
                    "fonts/tahoma.ttf");
            holder.txtViewTitle.setTypeface(face);
    
            holder.txtViewTitle.setText(title[position]);
            holder.txtViewDescription.setText(description[position]);
    
    
        } catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
        }
    
        Button record = (Button) convertView.findViewById(R.id.record);
    
        Button stop = (Button) convertView.findViewById(R.id.stop);
        Button play = (Button) convertView.findViewById(R.id.play1);
        Button upload = (Button) convertView
                    .findViewById(R.id.audio_upload);
        record.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
    
            if (isplaying2 == true) {
    
            } else
            { 
                if (b_Flag_Record_or_not == true) {
                } else {
                    try {
    
                        record.setBackgroundResource(R.drawable.record_green);
                        b_Flag_Record_or_not = true;
                        b_play_or_not = true;
    
                        flag_stop_position = position;
                        AuthHandler dataHandler = new AuthHandler();
                        AuthDataset dataset = dataHandler
                                .getParsednewJobdtl_DataSet();
    
                        System.out.println("dataset.getint1();"
                                + dataset.getint1());
                        // Login l = new Login();
                        String str_useid = RequestTo[position];
                        recorder = new AudioRecorder("/audiometer/shanesh"
                                + RequestId[position] + "-" + str_useid);
                        start_or_not = true;
                        recorder.start();
                        Toast.makeText(context, "Start Recording", Toast.LENGTH_LONG).show();
                        CountDownTimer countDowntimer = new CountDownTimer(
                                120000000, 1000) {
                            public void onTick(long millisUntilFinished) {
                            }
    
                            public void onFinish() {
                                try {
                                    Toast.makeText(
                                            context,
                                            "Stop recording Automatically ",
                                            Toast.LENGTH_LONG).show();
                                    recorder.stop();
                                } catch (Exception e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                        };
                        countDowntimer.start();
    
                    } catch (IOException e) {
                        Writer writer = new StringWriter();
                        PrintWriter printWriter = new PrintWriter(writer);
                        e.printStackTrace(printWriter);
                        String s = writer.toString();
    
                    }catch (Exception e) {
    
                    }
                }
    
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have listview with some listadapter after click on item from list I'd like
I have a ListView that I'm populating from a custom ListAdapter . Inside the
I have a custom listview and I am using a custom listadapter to display
I have a ListView with the following adapter: private class ListAdapter extends BaseAdapter {
I have a ListView that has some minor visual preferences that are set in
I currently have a tabview with a listview inside. I only have three items
I currently have a custom listview with two rows of text in each item,
I am using an ListAdapter to populate a ListView like this: static final String[]
I have a ListAdapter that contains a String array. When I click on any
I have created a listview that sits inside a larger activity (the list view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.