2012-12-28 70 views
1

我已經適應我的應用程序使用SherlockActivity,但因爲我已經這樣做,所以我不能得到任何點擊觸發我的網格視圖。下面是XML:SherlockActivity與GridView和onItemClick

<?xml version="1.0" encoding="utf-8"?> 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@android:color/white"> 

     <GridView 
      android:id="@+id/dashboard_grid" 
      style="@style/dashboard" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:listSelector="@android:color/transparent" 
      android:stretchMode="columnWidth" 
      android:verticalSpacing="20.0dip" /> 

    </RelativeLayout> 

我的onCreate方法:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.grid); 

    final ImageAdapter imageAdpt = new ImageAdapter(this); 

    GridView gridview = (GridView) findViewById(R.id.dashboard_grid); 
    gridview.setAdapter(imageAdpt); 

    gridview.setOnItemClickListener(new OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View v, int position, long id) { 
      Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show(); 
      Class<?> c = imageAdpt.getImageClass(position); 
      if(c != null){ 
       Intent intent = new Intent(MainActivity.this, c); 
       startActivity(intent); 
      } 
     } 
    }); 
} 

是否有做什麼重點?

+0

你在你的imageAdpt類GridView的充氣任何其他佈局? – Kanth

+0

在getView中:LayoutInflater vi =(LayoutInflater)mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); – nikolas

回答

0

嗨畢竟我是從之前的剩餘菜單充氣!

public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getSupportMenuInflater(); 
    inflater.inflate(R.menu.mainmenu, menu); 
} 

我它取代這個:

public boolean onCreateOptionsMenu(Menu menu) { 


    menu.add("Search") 
     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); 
    return true; 
} 
相關問題