我在 GridView 中添加了按钮,该按钮以编程方式添加,按钮的数量取决于字长每个按钮都有一个单词字符并在单击时隐藏该按钮,但我想在单击它时删除它。
这是代码
SpellAdapter.java
public class SpellAdapter extends BaseAdapter{
public Context context;
public char[] word;
public String spellWord1;
public SpellAdapter(Context context, char[] word, String orglWord)
{
this.context=context;
this.word=word;
spellWord1 = orglWord;
}
public int getCount() {
count=word.length;
return count;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup arg2) {
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.buttonlist, null);
}
final Button btn= (Button)v.findViewById(R.id.letterbtn);
btn.setText(word[position]+"");
btn.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
letters=btn.getText();
String word = letters.toString();
btn.setVisibility(View.GONE); // Here invisible the button.
}
});
return v;
}
}