0

I'm trying to send some data from one activity to another and it's sorta working but not like I want to work. Problem 1-Things are getting mixed up. On the Next Activity part of the listitem is going to an incorrect textView and part to the correct textview. Problem 2- I am only able to list 1 item on the new activity but I want to be able to send multiple listitems. I think the problem lies in combining different types of putExtra request to the same place like I do here.

.putExtra("inputPrice",(CharSequence)pick) .putStringArrayListExtra("list", listItems)

Ant help would be appreciated.

Sending Data to next Activity

final TextView username =(TextView)findViewById(R.id.resultTextView);
String uname = username.getText().toString();

final TextView uplane =(TextView)findViewById(R.id.inputPrice);                     
String pick = uplane.getText().toString();

final TextView daplane =(TextView)findViewById(R.id.date);                  
String watch = daplane.getText().toString();

 startActivity(new Intent(MenuView1Activity.this,RecordCheckActivity.class)
.putExtra("date",(CharSequence)watch)
.putExtra("Card Number",(CharSequence)uname)
.putExtra("inputPrice",(CharSequence)pick)
.putStringArrayListExtra("list", listItems)
);
finish();

This is the Next Activity

        Intent is = getIntent();
    if (is.getCharSequenceExtra("Card Number") != null) {
        final TextView setmsg = (TextView)findViewById(R.id.saleRccn);
        setmsg.setText(is.getCharSequenceExtra("Card Number"));             
    }
        Intent it = getIntent();
    if (it.getCharSequenceExtra("date") != null) {
        final TextView setmsg = (TextView)findViewById(R.id.saleTime);
        setmsg.setText(it.getCharSequenceExtra("date"));                
    }
    Intent id1 = getIntent();
    if (id1.getCharSequenceExtra("inputPrice") != null) {
        final TextView setmsg = (TextView)findViewById(R.id.saleName);
        setmsg.setText(id1.getCharSequenceExtra("inputPrice"));
    }
    ArrayList<String> al= new ArrayList<String>();
    al = getIntent().getExtras().getStringArrayList("list");
    saleNotes= (TextView) findViewById(R.id.saleNotes); 
    saleNotes.setText(al.get(0));
SmulianJulian
  • 801
  • 11
  • 33
  • Post your error Log please – Ashish Dwivedi Jun 07 '13 at 07:07
  • No errors. "list" is getting sent to saleNotes like it should but only one instance of list. List is showing up in New Activity in "saleRccn" – SmulianJulian Jun 07 '13 at 07:11
  • The two answers are helpful but I'm still having trouble getting the ArrayList – SmulianJulian Jun 07 '13 at 07:40
  • see my answer below. The reason list is showing up is you are using it correctly through getExtras whereas you are not using it for your other variables. Also you are only trying to access the first element of your array by al.get(0), that's why only the first item shows up. – kushyar Jun 07 '13 at 07:41

2 Answers2

2

Alright, a few things:

First of all you do not need to cast your strings as CharSequence.

Second thing,

Define intent, add your extras and only then call startActivity as below:

Intent intent = new Intent(MenuView1Activity.this,RecordCheckActivity.class);
intent.putExtra("date", watch);
startActivity(intent);

Third, when retrieving the intent create a bundle first as below:

Bundle extras = getIntent().getExtras();
String date = extras.getString("date");

EDIT:

Here is how you convert your entire array list to one single string and add it to your textview.

String listString = "";

for (String s : al)
{
    listString += s + "\t"; // use " " for space, "\n" for new line instead of "\t"
}

System.out.println(listString);
saleNotes.setText(listString);

Hope this helps!

kushyar
  • 1,191
  • 1
  • 6
  • 10
1

Try this, Don't use CharSequence just put string value

startActivity(new Intent(MenuView1Activity.this,RecordCheckActivity.class)
.putExtra("date",watch)
.putExtra("Card Number",uname)
.putExtra("inputPrice",pick)
.putStringArrayListExtra("list", listItems)
);

And get like this

  Intent is = getIntent();
if (is.getCharSequenceExtra("Card Number") != null) {
    final TextView setmsg = (TextView)findViewById(R.id.saleRccn);
    setmsg.setText(is.getStringExtra("Card Number"));             
}
MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22