Add ListView to-WPS Office Sketchware
Add ListView to-WPS Office Sketchware
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.
3. Now go to the CustomView drawer_main and add a LinearV linear1. Set it's width as MATCH_PARENT.
7. In the onCreate event, after adding items to the list, use an add source directly block and put following
codes in it.
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
listview1.setLayoutParams(lp1);
_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.
@Override
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;
}});