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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:12:40+00:00 2026-05-22T21:12:40+00:00

I have a ListActivity: public class MedTime extends ListActivity { /** Called when the

  • 0

I have a ListActivity:

public class MedTime extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      setContentView(R.layout.no_elements_l);

      String[] receipts = getResources().getStringArray(R.array.receipts_array);
      setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, receipts));

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

      lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
          // When clicked, show a toast with the TextView text
          Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
              Toast.LENGTH_SHORT).show();


        }

I’d like: when user clicks on list item, new activity named “view” launches. In addition, i need to say to this “view” activity which element from list called it. For example, if I click to 3rd element of list, activity “view” must be started and show me text = 3rd element of string array. The code fragment of “view” is here (value of i in last line must be sent by main activity to this, in my example i=3):

String[] receipts = getResources().getStringArray(R.array.receipts_array);
    TextView tv = new TextView(this);
    tv.setText(receipts[i]);

Please, tell me how to 1) launch “view” activity when user click a list item; 2) how to launch in this case “view” with the parameter that describes number of item selected?

  • 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-22T21:12:41+00:00Added an answer on May 22, 2026 at 9:12 pm

    Add the item position to your intent and start the new activity.

    ....
    Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
        Toast.LENGTH_SHORT).show();
    
    Intent intent = new Intent(MedTime.this, NewActivity.class);
    intent.putExtra("item", position);
    startActivity(intent);
    

    Then in the activity you started, extract the item in onCreate() from the intent.

    Intent intent = getIntent();
    
    int id = intent.getIntExtra("item", -1);
    
    if (id != -1) {
        Log.d(TAG, "Received item: " + id);
    }
    

    After this I can’t say what you wanna do. One possibility is to get the string value from your array as.

    String[] receipts = getResources().getStringArray(R.array.receipts_array);
    String myItem = receipts[id]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ListViewActivity public class SelectActivity extends ListActivity { protected void onCreate(Bundle savedInstanceState) {
I have an activity that extends ListActivity and implementsOnScrollListener: public class RecentItemsList extends GenericListActivity
I have an activity: public class Notepadv1 extends ListActivity { public static final int
I have a class defined as public class viewGroups extends ListActivity Somewhere in the
I have the following code snippet. public class ImageStoreActivity extends ListActivity { private DBHelper
i have created a custom dialog class public class NewPost extends Dialog { //
By using the following code. BuyActivity.java public class BuyActivity extends ListActivity { public void
i have created a My custom listActivty by extending ListActivity like this. public class
Here is my code for a simple cursor adapter. public class CursorList extends ListActivity
I am using a CursorAdapter to handle my ListActivity : public class Mclass extends

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.