I want gridview with buttons. following is the code of main page.
GridView gridview1 = (GridView) findViewById(R.id.gridview);
gridview1.setAdapter(new Buttonadapter(this));
gridview1.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View arg1, int position, long id)
{
TextView temp=(TextView)arg1;
CharSequence temp2=temp.getText();
Intent myIntent = new Intent(arg1.getContext(), Diseasemain.class);
myIntent.putExtra("disease", temp2);
startActivityForResult(myIntent, 0);
}
});
here is the code of buttonadapter class
public class Buttonadapter extends BaseAdapter {
private Context mContext;
public Buttonadapter(Context c)
{ mContext = c; }
public int getCount()
{ return mThumbIds.length; }
public Object getItem(int position)
{ return null; }
public long getItemId(int position)
{ return 0; } // create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent)
{ Button btn;
if (convertView == null)
{ // if it's not recycled, initialize some attributes
btn = new Button(mContext);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});
btn.setLayoutParams(new GridView.LayoutParam(85,85));
btn.setPadding(8, 8, 8, 8);
}
else
{
btn = (Button) convertView;
}
btn.setText(mThumbIds[position]);
return btn; }
private String[] mThumbIds =
{
"hi",
"bye",
"heelo"
}
;}
the problem is whenever I click on any button its not firing the onclick event nd not starting the next page also.
looks like the empty onclick method in your adapter is stopping
the itemclick listener from firing.
Try putting the code that starts the next page in the onclick instead.