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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:17:23+00:00 2026-06-17T04:17:23+00:00

I am fairly new to Android programming and trying to set items in a

  • 0

I am fairly new to Android programming and trying to set items in a listview upon loading the information from internal storage.

I have two global arrays that I am using: first one is a String array that has the names of the items in the list, and the second is a boolean array that keeps track of which items are crossed out. I am using a TextView in the listview.

main_activity.xml:

<ListView
        android:id="@+id/listViewMyList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
</ListView>

rowlayout.xml:
<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="3dp"
    android:layout_marginBottom="3dp"
    android:text="@+id/label" />

I have created an onClickListener() which successfully updates the state of each list item:

public class MainActivity extends Activity
{
// Initialize the list (global list values)
String[] values = new String[0]; // array of items for the list
boolean[] checkedVals = new boolean[0]; // keep track of which items are crossed-off
String localFileName = "myListData.csv";

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // read the data from file if present
    readListFromFile();        

    // find the ListView
    ListView lst = (ListView) findViewById(R.id.listViewMyList);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.rowlayout, R.id.label, values);
    lst.setAdapter(adapter);

    // define what happens on click
    lst.setOnItemClickListener(new OnItemClickListener()
    {
          public void onItemClick(AdapterView<?> parent, View view,int position, long id)
          {
              // read crossed status and set text flags for strikethrough                 
              if (checkedVals[position])
              {                   
                  TextView text1 = (TextView)view.findViewById(R.id.label);
                  text1.setPaintFlags(text1.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
                  text1.setTextColor(0xff000000);
                  checkedVals[position] = false;
              }
              else
              {
                  TextView text1 = (TextView)view.findViewById(R.id.label);
                  text1.setPaintFlags(text1.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                  text1.setTextColor(0xff888888);
                  checkedVals[position] = true;
              }
              // save the data in a file
              saveListToFile();
          }
    });

}

So this code works fine for crossing out and un-crossing out the items. I don’t know how can I cross-out some of the items (determined by the checkedVals boolean array) without clicking or any activity when I load the list.

Thanks in advance.

  • 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-17T04:17:24+00:00Added an answer on June 17, 2026 at 4:17 am

    You need to create a custom Adapter by extending ArrayAdapter and overriding getView().

    The getView() method loads every row’s layout, this is where you should check if the row is in your checkedVals array and draw with the appropriate flags. This Google Talk by an Android lead programmer, Romain Guy, provide a wealth of information about best practices on how to do this.

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

Sidebar

Related Questions

So I am fairly new to android programming. I have a database and I
I have just began opengl programming in android and i am fairly new to
I am fairly new to android programming (but not to Java programming). I have
I'm fairly new to android programming (making the switch from Windows programming to Mobile
I'm fairly new to Android programming and to Java in general, but I have
I'm fairly new to Android programming and have been searching around for some pointers
So I'm fairly new to Android Development and Programming in general... I have a
I'm fairly new to android programming, and I have the following situation: I'd like
I fairly new to programming for the Android platform and have some question about
I'm fairly new to Android programming. I'm trying to create an animation of a

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.