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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:48:57+00:00 2026-06-17T10:48:57+00:00

I have a ListView – getListView() of a ListActivity . The ListView is populated

  • 0

I have a ListView – getListView() of a ListActivity. The ListView is populated correctly and thats all fine.

Once any ListView item is clicked, it opens up a dialog consisting of 4 title TextViews and 4 user input Number EditTexts. I want to attach a Tag object to each of those EditText or to the ListView item however possible and keep track any changes made to the EditText using a TextWatcher.

i.e. In the Textwatcher if any changes are made to the text it is updated in the corresponding tag.

This would allow me to set the EditText text to any pre-existing values that have already been set.

The PROBLEM is that once the Dialog comes up, I enter EditText values and press positive button to dismiss. When I go to open again and retrieve tag to set EditText values before displaying values, they are all 0 (Except position – which is rather unimportant)

My onListItemClick code can be seen below.

// On Routine Selected
@Override
protected void onListItemClick(ListView l, View view, int position, long id)
{       
    // Get the tag from 'v'
    if (view.getTag() == null)
    {           
        // Create a new Set object and set that as the tag
        Set newTag = new Set(position);         
        view.setTag(newTag);
    }

    // Getting the Set tag from the ListView item
    Set vTag = (Set) view.getTag();

    /* ** Now an AlertDialog is presented to the user with a custom inflated view including EditTexts ** */

    // Getting an inflater (getLayoutInflater()) also works
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Inflating the XML defined layout as a view
    final View setView = inflater.inflate(R.layout.set_dialog, null);

    // Get EditText XML references
    EditText etReps = (EditText) setView.findViewById (R.id.etReps);
    EditText etIntensity = (EditText) setView.findViewById (R.id.etIntensity);
    EditText etPosition = (EditText) setView.findViewById (R.id.etPosition);
    EditText etChange = (EditText) setView.findViewById (R.id.etChange);        

    Log.d(TAG, "vTag.getReps(): " + (vTag.getReps() + 1));

    try
    {
        // Set the EditText values to values from the Set Tag
        etReps.setText(String.valueOf(vTag.getReps()));
        etIntensity.setText(String.valueOf(vTag.getIntensity()));
        etPosition.setText(String.valueOf(vTag.getPositionInExercise()));
        etChange.setText(String.valueOf(vTag.getIntensityChange()));        

        // Add Custom TextWatcher listener to all EditTexts
        etReps.addTextChangedListener(new MyTextWatcher(setView));
        etIntensity.addTextChangedListener(new MyTextWatcher(setView));
        etPosition.addTextChangedListener(new MyTextWatcher(setView));
        etChange.addTextChangedListener(new MyTextWatcher(setView));
    }
    catch (Exception e)
    {
        Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
    }

    // Create a new Builder to create the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(ExerciseList.this);   

    builder.setTitle(vTag.getName());
    builder.setView(setView);       

    builder.setPositiveButton("Save", new OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
            if (which == dialog.BUTTON_POSITIVE)
            {
//              setView.setTag(tag);
                dialog.dismiss();
            }
        }           
    });

    builder.show();
}   

MyTextWatcher code..

//Custom Watcher
class MyTextWatcher implements TextWatcher
{
    View view;

    public MyTextWatcher(View setView)
    {
        view = setView;
    }

    @Override
    public void afterTextChanged(Editable editable)
    {
        String newText = editable.toString();
        Set tag = (Set) view.getTag();

        switch (view.getId())
        {
        case R.id.etReps:
            tag.setReps(Integer.parseInt(newText));
            break;

        case R.id.etIntensity:
            tag.setIntensity(Integer.parseInt(newText));
            break;

        case R.id.etPosition:
            tag.setPositionInExercise(Integer.parseInt(newText));
            break;

        case R.id.etChange:
            tag.setIntensityChange(Integer.parseInt(newText));
            break;
        }       
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after){}

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count){}       
}

Any advice or steers in the direction would be great!

  • 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-17T10:48:58+00:00Added an answer on June 17, 2026 at 10:48 am

    It turns out for this case, a TextWatcher is not need at all. The main problem was to do with the scope of my vTag object.

    TextWatcher updates with every character as well, that doesn’t really benefit me and is just unneccesary computation.

    Declaring my EditText XML references final (The ones which I assigned to the Tag object of each ListItem view) means I can update the tag in the positive Button listener.

    Benefits and learning outcomes:

    • Only performs operations with the tags once, when the user presses the positive button, as opposed to every change of character in the EditText.
    • The use of final almost always increases speed, though normally get marginally.
    • This way also allows the user to opt out with a negative button in which case no tag updates take place. With the TextWatcher, all sorts of updates would have taken place with the user just pressing Cancel and negating them all.

    TextWatcher definitely has a place, however this wasn’t it.

    Just thought I’d contribute my finding and reasoning!

    Cheers

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

Sidebar

Related Questions

I have a ListView populated by a string-array. I want to select an item
I have ListView which is saving all data to database. For adding i have
I have a ListView and each item have a TextView. I would like add
I have listview with some listadapter after click on item from list I'd like
I have a ListView and I want to specify the selection (item) mode. In
I have ListView , populated by an SQLITE table, that is updated by bluetooth
If I have listview control with a button in the item template, how do
I have a ListView where each item has a checkbox. Initially there are no
I have listview with combox=true containg images. Each item is assigned a tag. I
i have listview and editText ,i need to scroll the last item of 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.