0% found this document useful (0 votes)
413 views4 pages

Add ListView to-WPS Office Sketchware

This document provides steps to programmatically add a ListView to the navigation drawer in a Sketchware Android project. The steps include: 1) Enabling AppCompat and Design libraries, 2) Adding a LinearLayout to the drawer CustomView, 3) Creating a string list of activity names, 4) Programmatically creating the ListView, setting its layout params and adapter, and adding it to the LinearLayout, and 5) Adding a click listener to start the corresponding activities.

Uploaded by

Miko Mik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
413 views4 pages

Add ListView to-WPS Office Sketchware

This document provides steps to programmatically add a ListView to the navigation drawer in a Sketchware Android project. The steps include: 1) Enabling AppCompat and Design libraries, 2) Adding a LinearLayout to the drawer CustomView, 3) Creating a string list of activity names, 4) Programmatically creating the ListView, setting its layout params and adapter, and adding it to the LinearLayout, and 5) Adding a click listener to start the corresponding activities.

Uploaded by

Miko Mik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Add ListView to Navigation drawer

May 06, 2018

In the latest version of Sketchware (v2.2.2), appcompat-v7 and design have been added, and we can now
add a navigation drawer to our project. This navigation drawer uses a CustomView. But the CustomView
in Sketchware doesn't have option to add a ListView.

In order to add a ListView to the drawer, we have to create the ListView programmatically and then add
it to the drawer. To know how it can be done follow the steps given below.

1. In your Sketchware android project, go to Library manager and switch on AppCompat and Design.

2. In View manager, go to MainActivity.java and select Navigation Drawer Activity.

3. Now go to the CustomView drawer_main and add a LinearV linear1. Set it's width as MATCH_PARENT.

4. Create a new String list mylist.

5. Create a new Intent component i.

6. Now suppose you have five other activities SettingsActivity.java, NotesActivity.java,


FeedbackActivity.java, PrivacyActivity.java, and AboutActivity.java.
Add a word for each of these activities to the String list mylist, in the onCreate event.

7. In the onCreate event, after adding items to the list, use an add source directly block and put following
codes in it.

ListView listview1 = new ListView(this);

LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

listview1.setLayoutParams(lp1);

listview1.setAdapter(new ArrayAdapter(getBaseContext(), android.R.layout.simple_list_item_1, mylist));

_drawer_linear1.addView(listview1);

Note that in this code mylist is the name of the String list, _drawer_linear1 represents the linear1 added
in the CustomView drawer_main.

This code creates a new ListView listview1, sets it's LayoutParams, sets it's Adapter, and adds it to the
LinearLayout linear1 in CustomView drawer_main.

8. After this add another add source directly block and put codes for setting OnItemClickListener for the
ListView.

listview1.setOnItemClickListener( new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(

AdapterView _parent, View _view, final int _position, long _id) {


switch (_position){

case 0:

i.setClass(getApplicationContext(), SettingsActivity.class);

startActivity(i);

break;

case 1:

i.setClass(getApplicationContext(), NotesActivity.class);

startActivity(i);

break;

case 2:

i.setClass(getApplicationContext(), FeedbackActivity.class);

startActivity(i);

break;

case 3:

i.setClass(getApplicationContext(), PrivacyActivity.class);

startActivity(i);

break;

case 4:

i.setClass(getApplicationContext(), AboutActivity.class);

startActivity(i);
break;

}});

Note that here i is Intent component.

9. Save and run the project.

You might also like