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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:12:00+00:00 2026-06-17T05:12:00+00:00

I’m new to programming for Android (and Java) and have managed to get a

  • 0

I’m new to programming for Android (and Java) and have managed to get a custom adapter working, but am stuck on how to update textViews inside of it. Below you will see my score_save function with the code I want, but I’m not sure how to apply this to all rows of my adapter at once.

public class MainActivity extends Activity {

private ListView listView1;
private int currentPlayer;
private int currentScore;
ArrayList<Integer> allScoreChange = new ArrayList<Integer>();
ArrayList<Integer> allScore = new ArrayList<Integer>();

Button button_add, button_add_big, button_sub, button_sub_big,
        button_add_num, button_save;

TextView name;
TextView score;
TextView scoreChange;

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

    Score score_data[] = new Score[] { new Score("NameA"),
            new Score("NameB"), new Score("NameC"), new Score("NameD"),
            new Score("NameE") };

    //sets score lists to 0
    for (int i = 0; i < 5; i++) {
        allScoreChange.add(0);
        allScore.add(0);
    }

    ScoreAdapter adapter = new ScoreAdapter(this,
            R.layout.listview_item_row, score_data);

    listView1 = (ListView) findViewById(R.id.listView1);

    listView1.setAdapter(adapter);
    listView1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            currentScore = allScoreChange.get(position);
            // Gets fields from current row
            score = (TextView) view.findViewById(R.id.txtScore);
            scoreChange = (TextView) view.findViewById(R.id.txtScoreChange);

            currentPlayer = position;

        }

    });
    button_save.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            score_save();
        }
    });

}

    public void score_save() {

    // this needs to go through all rows of listview
    currentPlayer = 0;

    // update array with new score
    allScore.set(currentPlayer, allScore.get(currentPlayer)
            + allScoreChange.get(currentPlayer));

    // display new score
    score.setText(allScore.get(currentPlayer));

    // reset score change to zero
    allScoreChange.set(currentPlayer, 0);

    // display score change as blank
    scoreChange.setText("");

    }

}

Here’s the XML for the row, I want to update txtScoreChange and txtScore with the values out of the allScoreChange and allScore ArrayLists. I cut out the code that defines these lists, in case you’re wondering.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10dp" >

<TextView
    android:id="@+id/txtTitle"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:layout_weight="70"
    android:text="Name"
    android:textColor="#000000"
    android:textSize="22sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/txtScoreChange"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginBottom="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:layout_weight="15"
    android:textColor="#ff0000"
    android:textSize="22sp"
    android:gravity="right" />

<TextView
    android:id="@+id/txtScore"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginBottom="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:layout_weight="15"
    android:text="1"
    android:textColor="#666666"
    android:textSize="22sp"
    android:gravity="right" />

Here’s my adapter:

public class ScoreAdapter extends ArrayAdapter<Score>{

    Context context; 
    int layoutResourceId;    
    Score data[] = null;

    public ScoreAdapter(Context context, int layoutResourceId, Score[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ScoreHolder holder = null;

        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new ScoreHolder();
            holder.txtScore = (TextView)row.findViewById(R.id.txtScore);
            holder.txtScoreChange = (TextView)row.findViewById(R.id.txtScoreChange);
            holder.txtName = (TextView)row.findViewById(R.id.txtName);

            row.setTag(holder);
        }
        else
        {
            holder = (ScoreHolder)row.getTag();
        }

        Score scoreData = data[position];
        holder.txtName.setText(scoreData.name);
        holder.txtScore.setText(scoreData.score);

        return row;
    }



    static class ScoreHolder
    {
        TextView txtScore;
        TextView txtName;
        TextView txtScoreChange;
    }
}
  • 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-17T05:12:02+00:00Added an answer on June 17, 2026 at 5:12 am

    Call adapter.notifyDataSetChanged(). That will cause it to repopulate the listview, calling adapter.getView on all visible views. Have getView() set the correct values for its row.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.