Giter Club home page Giter Club logo

internlists's Introduction

InternLists

Assignment for internship interview using Android Studio. The task was to pass an array from one activity to another. In the first activity, have a button which loads the second activity and displays a list of the array data passed from the first.

Here is how I approached this problem:

  1. Create a string array called interns and populate it with data.
  2. Create a new activity called ListActivity which will display the array data in a ListView.
  3. Make a ListView in activity_list.xml and give it the id internList.
  4. Pass array interns from MainActivity to ListActivity using an Intent intentListActivity and the putExtra() intent method.
  5. Add attribute android:onClick="openListActivity" to ButtonView on MainActivity so that the method openListActivity runs and opens ListActivity when tapped.
  6. In ListActivity, collect interns array from MainActivity with getIntent().getStringArrayExtra("interns") and store in local string array called interns.
  7. Next, find a ListView to attach interns data to by using findViewById() method and setting to internListView.
  8. Create array adapter internsAdapter to map array data to ListView.
  9. Set internsAdapter to internListView with setAdapter() method.

My Process

Originally, when I first made/committed this code, it did not display the array data in the ListActivity. In fact, the application crashed upon running it. After submission, I found that this was because I used the incorrect method to extract the data passed from the MainActivity. Instead of using getStringArrayExtra("interns"), I mistakenly used getStringArrayListExtra("interns"), which caused a null-object error in Android Studio.

This was not compatible with the putExtra() method on the intentListActivity intent I created in MainActivity. Another option might have been to use putStringArrayListExtra() on the intent instead to pass the data to ListActivity.

internlists's People

Contributors

yramocan avatar

Watchers

James Cloos avatar yar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.