Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically populate a button value android
    primarykey
    data
    text
    <p>I have seen lots of example to which one use a if condition or a case statement to programmatically change the conditions of elements...yadda yadda. I need to change the value of a button based on what the user clicks. Below is the code that I currently have.</p> <pre><code> Button btnOpenPopup = (Button)findViewById(R.id.polarity); btnOpenPopup = (Button) findViewById(R.id.color); final Button finalBtnOpenPopup = btnOpenPopup; btnOpenPopup.setOnClickListener(new Button.OnClickListener(){CONTINUES TO OTHER FUNCTIONS } </code></pre> <p>I basically need to know what button was pressed. Then dynamically populate it into findViewById() function. i.e.</p> <pre><code>btnOpenPopup = (Button) findViewById(R.id.DYNAMTICVALUEOFBUTTONUSERHASPRESSED); </code></pre> <p>This way by the time it gets to the final Button part of the code it will have the value to which the user clicked on. Code works if I only want to have one button or a page mile deep in different configuration (not ideal).</p> <p>All the examples I have seen so far are after the user clicks the button (which is what I want) but they name the buttons name statically like above code shows but very much static.</p> <p>Hope that all makes sense. </p> <p><strong>UPDATE:</strong></p> <p>I think I may have confused the situation. Below is the remaining code. Hopefully this will provide context. The btnOpenPopup needs to remain the same as it's used in the call to execute the command for a new window to actually popup. Hopefully this will provide a bit more context for what I'm trying to achieve. </p> <pre><code> final Button finalBtnOpenPopup = btnOpenPopup; btnOpenPopup.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) {LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); View popupView = layoutInflater.inflate(R.layout.meditationpopup, null); //set the title of the popup TextView titletext = (TextView) popupView.findViewById(R.id.chakratitle); titletext.setText(activityName); if (activityName.equals("Root")) { switch (arg0.getId()) { case R.id.color: //Rename the string so to get the value from the string xml String stringName = activityName.toLowerCase().replaceAll(" ","")+"color"; TextView desctext = (TextView) popupView.findViewById(R.id.popupDesc); desctext.setText(getString(getStringResource(getApplicationContext(),stringName))); break; case R.id.polarity: //Rename the string so to get the value from the string xml String polarityString = activityName.toLowerCase().replaceAll(" ","")+"polarity"; TextView polarityDesc = (TextView) popupView.findViewById(R.id.popupDesc); //polarityDesc.setText(activityName); polarityDesc.setText(getString(getStringResource(getApplicationContext(),polarityString))); break; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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