0

I have a CardScrollView with several items in the list and I'd like to further expand upon a selected item with more information so for example:

  1. User swipes to a card
  2. user taps the side (or uses voice)
  3. the user selects "More Info" from the menu
  4. (NOT SURE ON THIS PART) A new activity launches with details from that card (these details are stored in the object)

Here is my code and it is failing at the text view part (this code is inside the mainactivity.java

case R.id.settings_3: //More Info
           Log.v("Option_selected", "More Info " + jCardScrollView.getSelectedItemPosition());
           List<Stuff> stuff = currJobList.getList();
           String textDesc = stuff.get(jCardScrollView.getSelectedItemPosition()).getStuffDesc();
           TextView view = (TextView) findViewById(R.id.init_text);
           view.setText(textDesc); // add the description text into new activity

           // launch the activity
           Intent infoIntent = new Intent(this,MoreInfoActivity.class);
           startActivity(infoIntent);
cat
  • 91
  • 10

2 Answers2

2

You should insert the description textView in the new activity in onCreate non before it's opened. You can send the textDesc String through activity with

infoIntent.putExtra("textDesc", textDesc);

and retrieve it in the new activity with

Bundle extras = getIntent().getExtras();
String desc=(String) extras.getString("textDesc");
Cloud57
  • 66
  • 9
  • Would I then start the activity or does desc get passed into something? – cat Nov 19 '14 at 06:29
  • Yes use the startActivity with the intent wich you put the extra in it. Then retrieve in in onCreate (of the new activity) with the code i wrote. – Cloud57 Nov 19 '14 at 09:32
  • Okay, upon trying this I receive the following error for glass https://gist.github.com/char-tay/ae443b2d47cb15a6bc68 – cat Nov 19 '14 at 16:21
  • It seems you have a nullPointer. I can't help you by just reading the exception, can you post the code? – Cloud57 Nov 20 '14 at 07:45
  • I figured out what you meant see answer below, thank you so much for your help – cat Nov 20 '14 at 09:50
0

Thanks for your help @Cloud57 I was attempting to change the text before calling the oncreate function, this is the second activity that is called

 protected void onCreate(Bundle savedInstanceState) {
    //call onCreate first
    super.onCreate(savedInstanceState);
    //set the content view before setting any text
    setContentView(R.layout.more_info);

    textV = (TextView) findViewById(R.id.init_text);
    Bundle extras = getIntent().getExtras();

    if(extras!=null){
        String j = (String) extras.get("textDesc");
        textV.setText(j);
    }
}
cat
  • 91
  • 10