GithubHelp home page GithubHelp logo

pamons12 / csci490-lab_3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from csci-370-mobileappdevelopment-s2021/csci490-lab_3

0.0 0.0 0.0 258 KB

Creating a ListView and using ArrayAdapter

Java 100.00%

csci490-lab_3's Introduction

CSCI490-Lab_3

Android provides the ListView class (amoung others) which are capable of displaying a scrollable list of items. This can be a complex topic, so we will cover the basics and you will introduced to deeper concepts as the semester progresses.

Problem

This lab will have you creating a listview that will contain your classes you have taken over the last two semesters. Have at least five classes to list, even if you have to fake it.

Purpose

This lab will introduce some basic features of the ArrayAdapter and the ListView.

Steps

Create Views:

  • Open Android Studio and create a basic project. Name the project whatever you like, ListViewDemo is a good candidate. Choose Your API of choice, but should be at least API 23: Android 6.0 (Marshmallow). Next choose just an Empty Activity.
  • In the activity_main.xml, replace the default TextView with
    <ListView
        android:id="@+id/class_schedule"
        android:layout_height="match_parent"
        android:layout_width="match_parent">
    </ListView> 
  • Create a Java reference in MainActivity.java.
  • Create a String Array with your classes over the last few semesters. Have at least five classes.
  • Create an ArrayAdapter with the Application Context, the Android provided android.R.layout.simple_list_item_1, and the array.
  • Have your ListView object set an adapter with the ArrayAdapter you created in the last step.
  • Run your application and test.

Add Click Listeners:

  • ListView affords you the option to apply listeners to each item in the list.
  • On your ListView object, set a OnItemClickListener and a OnItemLongClickListener. Create a different Toast message for each. NOTE: If you return false on the LongClickListener, it will all for other Listeners. Test your Click Listeners and observe how the regular click is automatically called after the long click.
  • Change the LongClickListener to return true and test again. Observe how the regular click no longer is called.

Style the ListView

  • Add the following lines to the ListView in activity_main.xml:
<ListView
    ...
    android:dividerHeight="5.0sp"
    android:divider="@android:color/black"
    android:padding="45sp">
</ListView>
  • Test your code one final time.
  • Share, commit, and push lab to your GitHub account

csci490-lab_3's People

Contributors

kabriggs991 avatar pamons12 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.