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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:04:18+00:00 2026-05-29T07:04:18+00:00

I have created a custom listview that is populated using a row.xml file. Each

  • 0

I have created a custom listview that is populated using a row.xml file. Each row contains two TextViews and an ImageView. I populate the TextView from a JSON file (but this works fine, so I think you can safely ignore this), and I populate the ImageView based on SharedPreferences…which is where the problem lies.

Basically the logic is this: Someone clicks on a row in the listview, if the associated activity is completed successfully, I inform SharedPreferences and then, once the user returns to the list, a switch/case reads the SharedPreferences file and updates the ImageView in that specific row, to display a green icon. If the user fails the Activity, the ImageView in that row displays a red icon. A blue icon is displayed next to the first uncompleted activity in the list.

I do this by running a switch/case command for the SharedPreferences in the View formation loop.

So…my problem: I open the list, everything works fine. The list displays a single blue icon, as expected. When I scroll down, I see another blue icon further down…which shouldn’t be there. OK, you’re thinking “you F**ked up your coding”. However – when I scroll back up the list, I see the blue icon has now ‘jumped’ from the expected list item, to the one below. I scroll back down again and I see the blue icon has multiplied – there are now two of them in two different rows, where none existed before. So I completed a task. A green icon appears where it should. I scroll up and down a few times and suddenly there are 3-4 green icons next to different list rows.

My only guess is that the recycler is freaking out. Am I right? Is there something I can do to fix this? I tried being sneaky – I used ‘setVisibility-GONE’ for rows that where imageview is not needed…after some scrolling though, there it is – it’s annoying greenness lighting up the row it cannot possibly be in. Here’s my source code:

public class MainList extends ListActivity {
static SharedPreferences statusSettings;
String jsonString;
static JSONObject json;
static JSONArray arrayTest;
static int bob = 3;


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    try {
        JSONObject e = arrayTest.getJSONObject(position);
        Intent intent = new Intent();
        intent.putExtra("clientName", e.getString("proj_name"));
        intent.putExtra("clientAddress", e.getString("c_address"));
        intent.putExtra("clientComments", e.getString("comments"));
        intent.putExtra("clientOrder", e.getString("order"));
        intent.setClass(MainList.this, ClientDetails.class);
        MainList.this.startActivity(intent);


    } catch (JSONException e) {
        // TODO Auto-generated catch block
        Log.e("JSON", "Problem creating object from array!");
        e.printStackTrace();
    }
}

private static class EfficientAdapter extends BaseAdapter {
    private LayoutInflater mInflater;


    public EfficientAdapter(Context context) {
        // Cache the LayoutInflate to avoid asking for a new one each time.
        mInflater = LayoutInflater.from(context);

    }

    public int getCount() {
        return arrayTest.length();

    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        // A ViewHolder keeps references to children views to avoid unneccessary calls
        // to findViewById() on each row.
        ViewHolder holder;

        // When convertView is not null, we can reuse it directly, there is no need
        // to reinflate it. We only inflate a new View when the convertView supplied
        // by ListView is null.
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.mainlist, null);

            // Creates a ViewHolder and store references to the two children views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.icon = (ImageView) convertView.findViewById(R.id.ivMainIcon);
            holder.textName = (TextView) convertView.findViewById(R.id.tvMainName);
            holder.textAddress = (TextView) convertView.findViewById(R.id.tvMainAddress);


            convertView.setTag(holder);
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        }

        // Bind the data efficiently with the holder.

        JSONObject e;
        try {
            e = arrayTest.getJSONObject(position);
            holder.textName.setText(e.getString("proj_name"));
            holder.textAddress.setText(e.getString("c_address"));   

            switch (statusSettings.getInt(e.getString("order"), 0)){
                case 1:
                    holder.icon.setVisibility(View.INVISIBLE);
                    break;
                case 2:
                    if(bob == 3){
                        holder.icon.setImageResource(R.drawable.next_delivery);
                        bob = 5;
                    }
                    break;
                case 3:
                    holder.icon.setImageResource(R.drawable.delivered_icon);
                    break;
                case 4:
                    holder.icon.setImageResource(R.drawable.undelivered_icon);
                    break;
            }


        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            Log.e("JSON", "Couldn't put one of JSON arrays into object");
            e1.printStackTrace();
        }

        return convertView;
    }

    static class ViewHolder {
        ImageView icon;
        TextView textName;
        TextView textAddress;

    }
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    jsonString = getIntent().getExtras().getString("jsonString");
    try {
        json = new JSONObject(jsonString);
        arrayTest = json.getJSONArray("client_list");
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        Log.e("JSON", "Couldn't create the JSON Array");
        e.printStackTrace();
    }
    setListAdapter(new EfficientAdapter(this));

}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    bob = 3;        
    statusSettings = getSharedPreferences("status", 0);

    setListAdapter(new EfficientAdapter(this));
}


}

Any help would be greatly appreciated.

/edit: in case you need it – here is the row.xml file:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/LinearLayout02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" >

    <TextView
        android:id="@+id/tvMainName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:text="Large Text"
        android:textColor="#FFFFFF"
        android:textSize="25dp" />

    <ImageView
        android:id="@+id/ivMainIcon"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_gravity="bottom"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="10dp"
        android:layout_weight="0"
        android:scaleType="fitXY" />
</LinearLayout>

<TextView
    android:id="@+id/tvMainAddress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="5dp"
    android:text="TextView"
    android:textSize="15dp" />

</LinearLayout>

Updated Switch/Case (courtesy of Brigham)…still using a half-assed solution with the bob variable though. At least everything now works as it should!:

switch (statusSettings.getInt(e.getString("order"), 0)){
                case 1:
                    holder.icon.setVisibility(View.INVISIBLE);
                    break;
                case 2:
                    if(bob.toString().equalsIgnoreCase("do it") || bob.toString().equalsIgnoreCase(e.getString("proj_name"))){

                        holder.icon.setVisibility(View.VISIBLE);
                        holder.icon.setImageResource(R.drawable.next_delivery);
                        bob = e.getString("proj_name");
                    }else{
                        holder.icon.setVisibility(View.INVISIBLE);
                    }
                    break;
                case 3:
                    holder.icon.setVisibility(View.VISIBLE);
                    holder.icon.setImageResource(R.drawable.delivered_icon);
                    break;
                case 4:
                    holder.icon.setVisibility(View.VISIBLE);
                    holder.icon.setImageResource(R.drawable.undelivered_icon);
                    break;
                default:
                    holder.icon.setVisibility(View.INVISIBLE);
                    break;
            }
  • 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-29T07:04:18+00:00Added an answer on May 29, 2026 at 7:04 am

    In your case 2, you only set the image if bob == 3. You should add an else clause and make the image invisible when bob != 3. You should also make sure to set the icon to visible before the switch statement since most of your cases require it to be visible.

    You should also consider adding a default case to your switch statement.

            holder.icon.setVisibility(View.VISIBLE);
            switch (statusSettings.getInt(e.getString("order"), 0)){
                case 1:
                    holder.icon.setVisibility(View.INVISIBLE);
                    break;
                case 2:
                    if(bob == 3){
                        holder.icon.setImageResource(R.drawable.next_delivery);
                        bob = 5;
                    } else {
                        holder.icon.setVisibility(View.INVISIBLE);
                    }
                    break;
                case 3:
                    holder.icon.setImageResource(R.drawable.delivered_icon);
                    break;
                case 4:
                    holder.icon.setImageResource(R.drawable.undelivered_icon);
                    break;
                default:
                    holder.icon.setVisibility(View.INVISIBLE);
                    break;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

friends, i have created custom title bar using following titlebar.xml file with code <?xml
We have created custom listview by using the Base adapter. List view contains Text
I have a Custom ListView created from XML Layout. I want to bind that
I have a custom listview row that contains a number of textView components. Instead
I currently have a custom listview with two rows of text in each item,
I have a ListView that is fed by an SQLiteDB. On each row returned,
I have created a custom listview that have one webview per element. My problem
I have created a custom titlebar for all my listview activities using the following
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a custom workflow activity that copies attachments from a case to

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.