2

I have a longClick method on a grid view that does not work for the the 0 index position of the underlying ArrayList. However, if I add only one 'SentenceButton' I can remove it but not if I add many 'SentenceButton's.

The primary code is as follows in the SentenceButton class:

    public boolean onLongClick(View view) {
    boolean result = false;
    SentenceButton btnSentence = (SentenceButton)view;
    ArrayList<SentenceButton> temp = Utility.getSentenceArray();
    if(temp.contains((SentenceButton)view));
             result = Utility.getSentenceArray().remove(btnSentence);
    Utility.getSentenceArray().trimToSize();
    SBActivity.getmSentenceAdapter().notifyDataSetChanged();        
    return result;

}

This part of the code is made to simply remove an errant entry.

This does not seem to work, ie. remove, the first element of Utility.getSentenceArray and only works intermittently on the other 'SentenceButtons'.

Strangely, the play sound and adding to the Sentence view from the fragment I am using as a content view only seems to work twice in a row and then seems to hang until I rotate the device. The relevant code follows in the SoundButton class:

    public void onClick(View view) {
    // To Do: add to current sentence
    SoundThread sndThread = new SoundThread();
    sndThread.start();
    Utility.getSentenceArray().add(new SentenceButton(mContext, (SoundButton)view));
    SBActivity.getmSentenceAdapter().notifyDataSetChanged();
}

This adds the content view 'SoundButton' as a 'SentenceButton' in the SentenceButton array. Even more strangely to me, if I rotate the device enough it seems to add the 'SoundButton' as a 'SentenceButton'. It even plays the 'SoundButton' as the rotation happens but not before. It as if the onClick of the SoundButton is queued somewhere.

The rotation code is as follows:

@Override
public void onConfigurationChanged(Configuration newConfig)
{
                if (getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE)
        {
                    setFragment(getmFrag());

                    mSentenceGridView.invalidate();



        }
        else if (getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT)
        {
            setFragment(getmFrag());
            mSentenceGridView.invalidate();
        }
        super.onConfigurationChanged(newConfig);

} 

Could someone help me with this. Definitely a noob here and of course will add any relevant info asked of me.

I am trying to write a soundboard to help my friend's relative communicate better.

Many thanks in advance and especially to a tutorial on a working soundboard.

  • I am writing this with a Kindle Fire as my testing device.

I discovered part of the problem was not having a proper id for the buttons I am creating

sum1nil
  • 41
  • 4

0 Answers0