Note that there are some explanatory texts on larger screens.

plurals
  1. POHow To Match Characters From Two TextViews
    text
    copied!<p>I would like to know is it possible and how I could take the characters (in this case numbers) from two TextViews and use those matching digits to perform an action based on the number matched?</p> <p>Like for example I have in my activity two forms of text supplied from a previous activity via getIntent().getExtras from EditText inputs and in this activity I'm using setText() on those two text data into two different TextViews (TextView A and TextView B).Now let's say if TextView A has a 5 and TextView B has a 5,I would like to perform an action based on that 5 getting matched or say if TextView A has two 3's and TextView B has only one 3,how could I perform and action based on that one match and one non-match?</p> <p>Sorry I don't have any code posted up it's just that in my activity I would like to accomplish this but I don't know where to start.</p> <p>UPDATE:I posted my code to give a better example.</p> <pre><code>package com.fullfrontalgames.numberfighter; import android.app.Activity; import android.os.Bundle; import android.text.TextUtils; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import com.urbanairship.UAirship; public class Versus extends Activity { @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); UAirship.shared().getAnalytics(); } DBAdapter db; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.versus); final DBAdapter db = new DBAdapter(this); db.open(); Bundle PassedOverAttackNumbers = getIntent().getExtras(); String AttackerNumbers = PassedOverAttackNumbers .getString("com.fullfrontalgames.numberfighter.ANumber2Pass"); Bundle PassedOverDefenderNumbers = getIntent().getExtras(); String DefenderNumbers = PassedOverDefenderNumbers .getString("com.fullfrontalgames.numberfighter.DNumber2Pass"); Button Fight = (Button)findViewById(R.id.Fight); Button Continue = (Button)findViewById(R.id.Continue); ImageView AAvatar = (ImageView)findViewById(R.id.AttackerAvatar); ImageView DAvatar = (ImageView)findViewById(R.id.DefenderAvatar); TextView AName = (TextView)findViewById(R.id.AttackerName); TextView DName = (TextView)findViewById(R.id.DefenderName); TextView Admg = (TextView)findViewById(R.id.AttackerDamage); TextView Ddmg = (TextView)findViewById(R.id.DefenderDamage); TextView ANumbers = (TextView)findViewById(R.id.AttackerNumbers); TextView DNumbers = (TextView)findViewById(R.id.DefenderNumbers); TextView NBlock = (TextView)findViewById(R.id.NumbersBlocked); TextView NHit = (TextView)findViewById(R.id.NumbersHit); ANumbers.setText(AttackerNumbers); DNumbers.setText(DefenderNumbers); if (TextUtils.equals(AttackerNumbers, DefenderNumbers)) { NBlock.setText("1 Blocked"); NBlock.setText("2 Blocked"); NBlock.setText("3 Blocked"); NBlock.setText("4 Blocked"); NBlock.setText("5 Blocked"); NBlock.setText("6 Blocked"); NBlock.setText("7 Blocked"); NBlock.setText("8 Blocked"); NBlock.setText("9 Blocked"); } else { NHit.setText("1 Landed"); NHit.setText("2 Landed"); NHit.setText("3 Landed"); NHit.setText("4 Landed"); NHit.setText("5 Landed"); NHit.setText("6 Landed"); NHit.setText("7 Landed"); NHit.setText("8 Landed"); NHit.setText("9 Landed"); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload