0

Good morning folks (GMT)

I'm still learning Java, and Android development, I know this may be a simple question, but it's been driving me crazy for a while. I've searched Google and here and couldn't find the answer.

I have a variable listViewId, it's in my Offers class, its current value is null

Later in the code, Once a button is pressed from a ListView, the Variable is initialized with the ID of the ListView, This works fine however, and opens my new Activity page.

The issue i'm having, I need the listViewId variable to then Toast in the New Description Page.

I've tried the offers.var Code with no luck, I've even tried a Helper class, but when the variable is Toasted it is the null Value and not the value of the listViewID

Kind Regards

 public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.offers_layout, menu);

      eventslist.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            listviewIDEvents = (int) id; // takes listview ID from button pushed and stores the value to the variable listViewIDEvents
            Intent myIntent = new Intent(events.this, description.class);
            myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            events.this.startActivity(myIntent);
        }
    });

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.eventspage);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    Toast.makeText(this, "Welcome to the Description page " , Toast.LENGTH_SHORT).show();
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
  • 1
    Food for the thought: Try searching around `Intent` and passing values between activities. – Paresh Mayani Oct 13 '14 at 09:39
  • can you post some code – TootsieRockNRoll Oct 13 '14 at 09:40
  • sure, Edited post its in there now :) – Shaun Clark Oct 13 '14 at 09:43
  • I don't really understand what you mean by *I need the listViewId variable to then Toast in the New Description Page.* Don't you basically just want to send it over in an `Intent Extra`? – EpicPandaForce Oct 13 '14 at 09:46
  • I have a null Variable. ListViewIdEvents. its an INT once a button is pushed in a listview, the variable ListViewIDEvents, the value is then changed to the element ID For Example, if Element 5 is pushed the Variable ListViewIDEvents will have the value of 5, I need this value, To be displayed in another Activity on a toast! – Shaun Clark Oct 13 '14 at 09:48
  • based on the accepted answer, you did want to send it over as an intent extra :D – EpicPandaForce Oct 13 '14 at 11:17

1 Answers1

1

if you want to pass date to your activity class, you can use intent.putExtra() to send data to another activity here is the example also you can find similar solution here

 myIntent.putExtra("ID", listviewIDEvents);

and in activity you can do is :

 id= getIntent().getExtras().getString("ID");

also you can send integer too, hope it helps

Community
  • 1
  • 1
Syed Raza Mehdi
  • 4,067
  • 1
  • 31
  • 47