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 8986681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:36:29+00:00 2026-06-15T21:36:29+00:00

I have a listview to populate data with a CustomAdapter as shown below by

  • 0

I have a listview to populate data with a CustomAdapter as shown below by code.

1.) The listview rows are clickable and onItemClick I show up two buttons retake/review.

2.) When I click on other row the buttons which were visible on the previous row should hide.

3.) When I scroll the list all buttons are again invisible , that should not happen.

I have achieved the point no. 1 by this code , but how could I achieve 2,3. How could I modify getView() method of adapter or onItemClick() so that things work proper.

//Initialized listview with adapter

AttempListView.setAdapter(new AttemptedExcerciseAdapter(mAttempRecord,AttemptedExercise.this));

//A different adapter class to place values

public class AttemptedExcerciseAdapter extends BaseAdapter{

HashMap<Integer, AttemptedRecord> mHashMap;
Context mContext;
LinearLayout mLLButton;

public AttemptedExcerciseAdapter() {
    // TODO Auto-generated constructor stub
}

public AttemptedExcerciseAdapter(HashMap<Integer, AttemptedRecord> mAttempRecord,Context mContext) {
    this.mHashMap = mAttempRecord;
    this.mContext=mContext;
}
@Override
public int getCount() {
    return mHashMap.size();
}
@Override
public Object getItem(int arg0) {
    return null;
}
@Override
public long getItemId(int arg0) {
    return 0;
}


@Override
public View getView(final int position, View convertView, ViewGroup arg2) {
    if (convertView == null) {
        @SuppressWarnings("static-access")
        LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(AttemptedExercise.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.exerciselistlayout, null);
    }

    TextView attempChapter_name = (TextView) convertView.findViewById(R.id.TVchapterexercisechapterName);
    TextView attemptQues = (TextView) convertView.findViewById(R.id.tvexercisesuccessrate);
    TextView attemptSR = (TextView) convertView.findViewById(R.id.tvexerciseperquestiontime);

    Button ReviewButton = (Button) convertView.findViewById(R.id.ReviewButton);
    Button RetakeButton = (Button) convertView.findViewById(R.id.RetakeButton);
    LinearLayout mLLtext = (LinearLayout) convertView.findViewById(R.id.LLText);
    mLLButton = (LinearLayout) convertView.findViewById(R.id.LLButton);

    mLLButton.setVisibility(View.INVISIBLE);
    mLLtext.setVisibility(View.VISIBLE);
    System.out.println("data value is..."+position+mHashMap.get(position + 1).getChapter_name());

    attempChapter_name.setText(mHashMap.get(position+1).getChapter_name());
    attemptQues.setText(" " + mHashMap.get(position+1).getTimePerQues() + " sec/ques");
    attemptSR.setText(" " + mHashMap.get(position+1).getSuccess_rate() + " %");

    return convertView;
}

}

//Item click listener for listview

public class ExcerciseItemClickListener implements OnItemClickListener {

    ArrayList<Integer> rowNo=new ArrayList<Integer>();

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

        System.out.println("click working..."+arg2);

        arg1.findViewById(R.id.LLButton).setVisibility(View.INVISIBLE);

        rowNo.clear();

        rowNo.add(arg2);

        if(rowNo.size()==1)
        {   
        AttemptedRecord mRecordExcerciseItem = mAttempRecord.get(arg2 + 1);

        final int chapter_id = mRecordExcerciseItem.getChapter_id();
        final int test_id = mRecordExcerciseItem.getTest_id();
        final int subject_id = mRecordExcerciseItem.getSubject_id();

        System.out.println("attempted  list size is..."+mAttempRecord.size());

            arg1.findViewById(R.id.LLText).setVisibility(View.INVISIBLE);
            arg1.findViewById(R.id.LLTake).setVisibility(View.INVISIBLE);
            arg1.findViewById(R.id.LLButton).setVisibility(View.VISIBLE);

            Button review=(Button) arg1.findViewById(R.id.ReviewButton);
            Button retake=(Button) arg1.findViewById(R.id.RetakeButton);

            review.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    DBHelper mDbHelper = new DBHelper(AttemptedExercise.this);
                    mDbHelper.createOrOpenDatabase("Dashboard");
                    Cursor chpater_exercise_Cursor = mDbHelper.rawQuery("select current_test_id from practice_test_summary where test_id="+test_id+" order by test_datetime desc limit 1");

                    chpater_exercise_Cursor.moveToFirst();

                    Long current_test_id =chpater_exercise_Cursor.getLong(0);
                    chpater_exercise_Cursor.close();

                    System.out.println("value of current test id is...."+current_test_id);

                    Intent reviewIntent = new Intent(AttemptedExercise.this, PracticeReview.class);
                    reviewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
                    if (current_test_id > 0) {
                        reviewIntent.putExtra("current_test_id", current_test_id);
                        startActivity(reviewIntent);
                    }
                }
            });

            retake.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    System.out.println("test id value when test starts is... "+test_id);
                    Toast.makeText(AttemptedExercise.this, "chapter_id" + chapter_id + " course_id"  + " test_id" + test_id + " subject_id" + subject_id, Toast.LENGTH_LONG).show();
                    StartTest(4, subject_id, chapter_id, test_id);
                }
            });
        }
    }
    }
  • 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-06-15T21:36:31+00:00Added an answer on June 15, 2026 at 9:36 pm

    if you can mange to add ClickListeners of the list in getView like this

    convertView.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                curruntButtonClickPosition=position;
                                //Visible you button here
                                notifyDataSetChanged();
            }
        });
    

    and in getView

     if(curruntButtonClickPosition=position)
       //mLLButton visible
    else
      //mLLButton  invisible
    

    add curruntButtonClickPosition globle variable in AttemptedExcerciseAdapter class and init with -1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml data file and I want to populate a listview in
I have a listview that's populated by rows that get their data from a
I have a ListView view I need to populate using data I am fetching
I have two loaders, one to populate bind returned data to 2 TextViews and
I use ListView to populate my Menu and Price. I have 2 ListView s
Is it possible to populate a listview with a dataset? I have a function
I have an activity that extends ListView. I populate my list with the results
I have an Activity_A where there is a ListView whose data depends on a
I would like to create a listview with custom rows. I have created a
I have a listview that uses a customadapter based on the baseadapter. The listview

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.