0
我在GridView中添加按鈕,按鈕以編程方式添加,按鈕的數量取決於字長每個按鈕都有一個字的字符,並單擊時隱藏該按鈕,但我想單擊時刪除它。如何在單擊Android中的按鈕後從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;
}
}