我在网格视图上有一个 longClick 方法,该方法不适用于底层 ArrayList 的 0 索引位置。但是,如果我只添加一个“SentenceButton”,我可以删除它,但如果我添加许多“SentenceButton”则不能。
SentenceButton 类中的主要代码如下:
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;
}
这部分代码用于简单地删除错误条目。
这似乎不起作用,即。删除 Utility.getSentenceArray 的第一个元素,并且仅在其他“SentenceButtons”上间歇性地工作。
奇怪的是,播放声音并从我用作内容视图的片段添加到句子视图似乎只连续工作两次,然后似乎挂起,直到我旋转设备。SoundButton 类中的相关代码如下:
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();
}
这会将内容视图“SoundButton”作为“SentenceButton”添加到 SentenceButton 数组中。对我来说更奇怪的是,如果我将设备旋转得足够多,它似乎会将“SoundButton”添加为“SentenceButton”。它甚至会在旋转发生时播放“SoundButton”,但之前不会。就好像 SoundButton 的 onClick 在某处排队。
旋转代码如下:
@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);
}
有人可以帮我解决这个问题。绝对是这里的菜鸟,当然会添加任何询问我的相关信息。
我正在尝试写一个音板来帮助我朋友的亲戚更好地交流。
非常感谢提前,特别是关于工作音板的教程。
- 我用 Kindle Fire 作为我的测试设备来写这篇文章。
我发现部分问题是我正在创建的按钮没有正确的 ID