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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:37:59+00:00 2026-06-07T07:37:59+00:00

I have a ListView which is populated using a SimpleCursorAdapter. The row layout is

  • 0

I have a ListView which is populated using a SimpleCursorAdapter. The row layout is given below:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <TextView 
        android:id="@+id/row" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp" />

    <ImageView
        android:id="@+id/enable_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:padding="10dp"
        android:contentDescription="@string/image_description"
        android:src="@android:drawable/checkbox_off_background" />

</RelativeLayout>

What i want to do is to change the source of the imageview to something else based on some shared preference when the activity is created. This is the code that i use but it doesn’t work:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    long appliedProfileId = prefs.getLong("appliedProfileId", -1); 

    if(appliedProfileId != -1) {
        /*View rowView = (View) getListView().getAdapter().getView(info.psition, null, null);
        TextView textView = (TextView) rowView.findViewById(R.id.row);*/
        ListView listView = getListView();
        ListAdapter adapter = listView.getAdapter();
        View appliedRowLayout = (View) adapter.getView(getItemPositionByAdapterId(adapter, appliedProfileId), null, null);

        TextView textView = (TextView) appliedRowLayout.findViewById(R.id.row);
        Log.d("asdasd", textView.getText().toString());
        ImageView imageView = (ImageView) appliedRowLayout.findViewById(R.id.enable_image);
        imageView.setImageResource(android.R.drawable.checkbox_on_background);
        setListAdapter(adapter);
    }

This is the getItemPositionByAdapterId method:

private int getItemPositionByAdapterId(ListAdapter adapter, final long id)
{
    for (int i = 0; i < adapter.getCount(); i++)
    {
        if (adapter.getItemId(i) == id)
            return i;
    }
    return -1;
}

I am able to read the contents of the listview but cannot change them.. Pleas help 🙂

  • 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-07T07:38:00+00:00Added an answer on June 7, 2026 at 7:38 am

    You need to override the getView method for this listview. Check Customizing Android ListView Items

    You need to do something like this.

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    if (position == 0) // first element in the list
     {
       convertView.findViewById(R.id.image1).setImageURI(....)
     }
        and so on....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom listview that is populated using a row.xml file. Each
I have a listview which is populated by a SimpleCursorAdapter that is binding data
I have a ListView which is populated by a SQLite query in OnCreate using
I have a ListView which contains a text field that is populated using a
I have a ListView which is populated using a web service. I want to
I have a ListView which is populated using a CursorAdapter. I'd also like to
I have a ListView which is using a GridView to display a DataTable and
I have a ListView which contains custom rows. This custom row has following UI
I have an activity with a ListView which is populated through a custom ArrayAdapter.
I have a listview which loads its data from sqlite database. Each row in

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.