我在GridView
使用基本适配器时添加了按钮,当单击按钮然后隐藏时,按钮取决于字长。单击所有按钮后,GridView
我想检查是否GridView
为空显示另一个按钮。我想检查是否GridView
为空GridViewActivity.java
这是代码。
GridViewActivity.java
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.spellword);
txt=(TextView)findViewById(R.id.txtview);
image=(ImageView)findViewById(R.id.imgview1);
map.put("melon", R.drawable.melon);
image.setImageResource(map.get("melon"));
gridView=(GridView)findViewById(R.id.grid1);
gridView.setAdapter(new SpellAdapter(this,words,word));
detector = new SimpleGestureFilter(this, this);
}
SpellAdapter.java
public class SpellAdapter extends BaseAdapter{
public Context context;
public char[] word;
public SpellAdapter(Context context, char[] word, String orglWord)
{
this.context=context;
this.word=word;
}
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);
}
});
return v;
}
}