patternjavaMinor
Android Activity with a RecyclerView inflated by a big ArrayList
Viewed 0 times
recyclerviewandroidwithinflatedbigactivityarraylist
Problem
This Activity has got a
This is what an Element of the ArrayList looks like:
So it has got some images, two Strings and a Sound file.
This whole List is inflated into the RecyclerView at Activity's launch. This causes the Activity to have some lag when I scroll fast through the List.
How can I improve the performance of this class?
code:
```
public class ChordsListActivity extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener {
ArrayList chords;
ImageButton cerca;
RecyclerView recyclerView;
InterstitialAd chordsListAd;
boolean isPremium;
static final String PREFERENCES = "prefs";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chords_list);
SharedPreferences settings = getSharedPreferences(PREFERENCES,0);
isPremium = settings.getBoolean("status", false);
/** gets the list */
chords = new ArrayList<>();
ChordsList list = new ChordsList();
list.createList();
chords = list.getList();
/** inflates the list into the recyclerview */
recyclerView = (RecyclerView) findViewById(R.id.chords_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(ChordsListActivity.this, LinearLayoutManager.VERTICAL, false));
recyclerView.setHasFixedSize(true);
final ChordsListAdapter adapter = new ChordsListAdapter (this, chords);
recyclerView.setAdapter(adapter);
/** manages ads */
if (!isPremium) {
MobileAds.initialize(getApplicationContext(), "ca-app-pub-6723047396589178/2654753246");
RecyclerView that is inflated with an ArrayList that is ca. 400 Elements.This is what an Element of the ArrayList looks like:
chords.add(new Accordo(new int[]{
R.drawable.do_maggiore, R.drawable.do_maggiore_alt1, R.drawable.do_maggiore_alt2,
R.drawable.do_maggiore_alt3, R.drawable.do_maggiore_alt4, R.drawable.do_maggiore_alt5,
R.drawable.do_maggiore_alt6}, R.string.do_maggiore, "Do, Mi, Sol", R.raw.do_maggiore));So it has got some images, two Strings and a Sound file.
This whole List is inflated into the RecyclerView at Activity's launch. This causes the Activity to have some lag when I scroll fast through the List.
How can I improve the performance of this class?
code:
```
public class ChordsListActivity extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener {
ArrayList chords;
ImageButton cerca;
RecyclerView recyclerView;
InterstitialAd chordsListAd;
boolean isPremium;
static final String PREFERENCES = "prefs";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chords_list);
SharedPreferences settings = getSharedPreferences(PREFERENCES,0);
isPremium = settings.getBoolean("status", false);
/** gets the list */
chords = new ArrayList<>();
ChordsList list = new ChordsList();
list.createList();
chords = list.getList();
/** inflates the list into the recyclerview */
recyclerView = (RecyclerView) findViewById(R.id.chords_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(ChordsListActivity.this, LinearLayoutManager.VERTICAL, false));
recyclerView.setHasFixedSize(true);
final ChordsListAdapter adapter = new ChordsListAdapter (this, chords);
recyclerView.setAdapter(adapter);
/** manages ads */
if (!isPremium) {
MobileAds.initialize(getApplicationContext(), "ca-app-pub-6723047396589178/2654753246");
Solution
I don't know much about Android so I will comment on a more general concern with the code.
There is something I find makes your code difficult to read for me: I don't speak Italian. In fact, most programmers don't speak Italian...
Source: CommmitStrip: The story of a coder who doesn't speak English
Java, as most programming languages, is written in English, and so you can be assured that every Java programmer also speaks English to a reasonable extent. By writing your code (names, etc.) in English you make your code maintainable by any Java programmer, without them needing an Italian-English dictionary to help them follow along.
-
-
-
The
There is something I find makes your code difficult to read for me: I don't speak Italian. In fact, most programmers don't speak Italian...
Source: CommmitStrip: The story of a coder who doesn't speak English
Java, as most programming languages, is written in English, and so you can be assured that every Java programmer also speaks English to a reasonable extent. By writing your code (names, etc.) in English you make your code maintainable by any Java programmer, without them needing an Italian-English dictionary to help them follow along.
-
R.drawable.do_maggiore would be better as R.drawable.do_major.-
ImageButton cerca could have a few meanings.. do you mean search or run? After reading further down cerca = (ImageButton) findViewById(R.id.search); it's obviously search, but I had to scroll down the code to make sure.-
The
switch inside your onMenuItemClick also has quite a few Italian names, along with inconsistent naming e.g.: your information menu's Intent is called intent while the other Intent are legendaIntent, premiumIntent, email, shareIntent.Context
StackExchange Code Review Q#141701, answer score: 8
Revisions (0)
No revisions yet.