我不知道如何将图像按钮添加到我的网格视图中。我必须为每个图像按钮执行单独的代码,因为它们做的事情完全不同。我该怎么做?
我最终改用了表格布局
代码:
package com.mysoftware.mysoftwareos.launcher;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Import views
//Setup onClickListener for the buttons
//Setup GridView
}
@Override
public boolean onKeyDown(int KeyCode, KeyEvent event) {
if ((KeyCode == KeyEvent.KEYCODE_BACK)) {
//Do nothing to prevent the back button to kill the launcher
return true;
}
return super.onKeyDown(KeyCode, event);
}
public void onClick(View src) {
switch(src.getId()) {
}
}
}
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF8090A0" >
<GridView
android:id="@+id/appsGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:numColumns="3" >
</GridView>
</RelativeLayout>