我已经调整了我的应用程序以使用SherlockActivity但是因为我已经这样做了,所以我无法在网格视图上触发任何点击。下面是xml:
<?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 :(得分: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;
}