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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:33:14+00:00 2026-06-11T08:33:14+00:00

I have ArrayAdapter, where I set array of files: adapter = new ArrayAdapter<Item>(this, R.layout.file_manager,

  • 0

I have ArrayAdapter, where I set array of files:

adapter = new ArrayAdapter<Item>(this,
            R.layout.file_manager, R.id.checkedTextItem,
            fileList) 
            {


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // creates view
            LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.item, null);
            view.setFocusable(false);
            CheckedTextView textView = (CheckedTextView) view
                    .findViewById(R.id.checkedTextItem);

            // put the image on the text view
            textView.setCompoundDrawablesWithIntrinsicBounds(
                    fileList[position].icon, 0, 0, 0);

            textView.setTextColor(Color.WHITE);
            textView.setText(fileList[position].file);
            if(fileList[position].icon == R.drawable.directory_icon)
                textView.setCheckMarkDrawable(null);
            else if(fileList[position].icon == R.drawable.directory_up)
                textView.setCheckMarkDrawable(null);

            // add margin between image and text (support various screen
            // densities)
            int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
            textView.setCompoundDrawablePadding(dp5);

            textView.setFocusable(false);

            return view;

        }
    };

Then I want to change checkable state of CheckedTextView by item clicking. I do it like this:

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
     setContentView(R.layout.file_manager);
    lv = (ListView)findViewById(R.id.fileManagerList);
    loadFileList();
    file_list = findViewById(R.id.filesList);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    lv.setFocusable(false);
    lv.setAdapter(adapter);

    lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {
            //String selectedFromList = (lv.getItemAtPosition(myItemInt).toString());
            chosenFile = fileList[myItemInt].file;
            File sel = new File(path + "/" + chosenFile);

            if (sel.isDirectory()) {

                firstLvl = false;


                str.add(chosenFile);

                fileList = null;
                path = new File(sel + "");
                //adapter.notifyDataSetChanged();
                loadFileList();
                lv.setAdapter(adapter);


            }
            else if (chosenFile.equalsIgnoreCase("up") && !sel.exists()) {

                // present directory removed from list
                String s = str.remove(str.size() - 1);

                // path modified to exclude present directory
                path = new File(path.toString().substring(0,
                        path.toString().lastIndexOf(s)));
                fileList = null;

                // if there are no more directories in the list, then
                // its the first level
                if (str.isEmpty()) {
                    firstLvl = true;
                }

                loadFileList();
                lv.setAdapter(adapter);
            }
            else
            {
                View view = myAdapter.getChildAt(myItemInt);
                CheckedTextView textView = (CheckedTextView) view
                        .findViewById(R.id.checkedTextItem);        
                Toast toast = Toast.makeText(getApplicationContext(),textView.isChecked(), Toast.LENGTH_LONG);
                toast.show(); 

                textView.toggle();

                textView.setChecked(true);
            }

    }

});


}

The click event is handling properly. I can get the CheckedTextView item in else statement of onCreate() method – I detect its id and also can get the text of it. But when I try to toggle it or setCheckable – it can’t be handling. Nevertheless, when I toggle or setCheckable of all items in my adapter – check state can be changed…What can be the reason of it?

  • 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-11T08:33:15+00:00Added an answer on June 11, 2026 at 8:33 am

    because Android reuses views. When your list of checkable items is scrolled beyond the screen, the new items showing at the bottom are reused from previous ones. You need to
    keep track of the state of each item (a sparse array works well) and in each view, check
    the state from the array and set the checkedtextview accordingly.

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

Sidebar

Related Questions

I have a spinner set up like this: ArrayAdapter<String> states = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
I have set adapter to the MultiAutoCompleteTextView in my android application. ArrayAdapter<String> adapter =
I have a listview connected to a custom array adapter. This list shows information
I have a array list like this: private ArrayList<Locations> Artist_Result = new ArrayList<Location>(); This
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
This post will be heavy on images. I have created a custom ArrayAdapter and
I have a listview with custom array adapter, the view allows the user to
I have a white background but with this layout i am blocked because text
I'm pretty new to this, and I have a question that is probably pretty
I have an AutoCompleteTextView which is using an ArrayAdapter<android.location.Address> as its Adapter . The

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.