Note that there are some explanatory texts on larger screens.

plurals
  1. POThe value of the variable don't show in the other class
    text
    copied!<p>I make a program in Eclipse to Android and I have a problem. I have this class where I show the artists. Inside the onClick method I want to send the "value" of the clicked listitem.</p> <pre><code>...public class ArtistActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listview); String[] artists = getResources().getStringArray(R.array.artists_array); setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, artists)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { StringActivity sA = new StringActivity(); sA.setArtist(((TextView) v).getText().toString()); String asd = sA.getArtist(); //Toast.makeText(getApplicationContext(), asd/*((TextView) v).getText()*/, Toast.LENGTH_SHORT).show(); Intent i = new Intent().setClass(getApplicationContext(), AlbumActivity.class); startActivity(i); } }); }} </code></pre> <p>Inside onClick when I do it with Toast then it shows the picked item, but in the other class don't. Here are the code where I store the value:</p> <pre><code>public class StringActivity { private String artist=""; public String getArtist() { return(artist); } public void setArtist(String artist) { this.artist=artist; } public String toString() { return(getArtist()); }} </code></pre> <p>And here is the other class where it should show the value:</p> <pre><code>public class AlbumActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); StringActivity sA = new StringActivity(); String asd = sA.getArtist(); TextView textview = new TextView(this); textview.setText("Hello " + asd + " World!"); setContentView(textview); }} </code></pre> <p>The hello world is there just because to see that there is nothing wrong with the textview. Maybe the problem is that it don't refresh (it's stay the same from the launch of the program - because when I give a value for the artist string in the StringActivity class then it shows, but when I click on an item it stay the same) or there is another problem? Thanks!</p>
 

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