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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:57:00+00:00 2026-05-21T06:57:00+00:00

I make a program in Eclipse to Android and I have a problem. I

  • 0

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.

...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<String>(this, R.layout.list_item, artists));

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> 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);
            }
    });
}}

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:

public class StringActivity {
private String artist="";

public String getArtist() {
    return(artist);
}

public void setArtist(String artist) {
    this.artist=artist;
}

public String toString() {
    return(getArtist());
}}

And here is the other class where it should show the value:

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);
}}

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!

  • 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-05-21T06:57:00+00:00Added an answer on May 21, 2026 at 6:57 am

    The StringActivity you create in your onClick listener is only visible inside the listener, not in your second activity! You have to use Intent.putExtra() to push some extras into the Intent, then use Intent.getExtras() in your second activity to get them back.

    So change the onClick to:

    public void onItemClick(AdapterView<?> parent, View v, int position, long id) 
    {                   
       String artist = ((TextView) v).getText().toString();
       Intent i = new Intent().setClass(ArtistActivity.this, AlbumActivity.class);
       i.putExtra("artist", artist);
       startActivity(i);
    }
    

    And in the second activity’s onCreate you can do:

    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
    
       Bundle extras = getIntent().getExtras();
    
       String asd = extras.getString("artist");
       TextView textview = new TextView(this);
       textview.setText("Hello " + asd + " World!");
       setContentView(textview);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project in eclipse workspace. I would like to make another program
I have a program I want to make into a jar file, so I
I make this program :: #include<stdio.h> char *raw_input(char *msg); main() { char *s; *s
I want to make a program that will simulate a user browsing a site
I want to make a program that will read some number in string format
I have a program which consists of multiple projects in eclipse (working under ubuntu
If I make a program, with I want to make encrypted files, how can
I have made a program on eclipse. But how can I get the program
What are the arguments to put in eclipse subversion merge program arguments to make
I am trying to make an android game in eclipse (in windows). I keep

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.