2011-10-27 44 views
0

我想要gridview和buttons.folowing是主頁的代碼。Android按鈕的Grdidview

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); 
       } 
    }); 

這裏是buttonadapter類

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" 


     } 
;} 

的代碼problesm是每當我上的任意鍵單擊其NT射擊onclick事件ND不strting下一頁也。 請幫助..它緊急。 thnx提前..

回答

0

看起來像您的適配器中的空onclick方法正在停止 itemclick監聽器發射。 嘗試將啓動下一頁的代碼放在onclick上。