我想在广播组中制作网格视图
我做了当前的网格视图但是radiobuttons不在radiogroub中
我在谷歌搜索但我没有找到任何东西
这是我的类和xml文件,请帮助我
AddCtegory_Activity.java
public class AddCategory_Activity extends Activity {
ExpandableHeightGridView grid;
int[] web = {
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,11,12,13,14,15,16
} ;
int[] imageId = {
R.drawable.c_1,
R.drawable.c_2,
R.drawable.c_3,
R.drawable.c_4,
R.drawable.c_5,
R.drawable.c_6,
R.drawable.c_7,
R.drawable.c_8,
R.drawable.c_9,
R.drawable.c_10,
R.drawable.c_11,
R.drawable.c_12,
R.drawable.c_13,
R.drawable.c_14,
R.drawable.c_15,
R.drawable.c_16
};
@Override
protected void onCreate(Bundle savedInstanceState) {
/************************* Start Action Bar Function ************************************/
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(null);
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffffff")));
actionBar.setHomeAsUpIndicator(R.drawable.ic_back_icon);
actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP|ActionBar.DISPLAY_SHOW_TITLE);
/************************* End Action Bar Function ************************************/
setContentView(R.layout.activity_add_category_);
/*******************************************************/
CustomGridAdapterAddCategoryListColor adapters = new CustomGridAdapterAddCategoryListColor(AddCategory_Activity.this, web, imageId);
grid=(ExpandableHeightGridView)findViewById(R.id.color_grid);
grid.setExpanded(true);
grid.setAdapter(adapters);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(AddCategory_Activity.this, "You Clicked at " + web[+position], Toast.LENGTH_SHORT).show();
}
});
/********************************************************/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.add_category_, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是适配器
public class CustomGridAdapterAddCategoryListColor extends BaseAdapter {
private Context mContext;
private final int[] title;
private final int[] Imageid;
public CustomGridAdapterAddCategoryListColor(Context c, int[] title, int[] Imageid) {
mContext = c;
this.Imageid = Imageid;
this.title = title;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return title.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mContext);
grid = inflater.inflate(R.layout.add_new_category_grid_list_item, null);
RadioButton rp = (RadioButton) grid.findViewById(R.id.rbColor);
rp.setBackgroundResource(Imageid[position]);
rp.setId(title[position]);
} else {
grid = (View) convertView;
}
return grid;
}
}
这是网格项目
<?xml version="1.0" encoding="utf-8"?>
<RadioButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="40pt"
android:layout_height="40pt"
android:id="@+id/rbColor"
android:button="@null"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/button"/>
以及最终的XML布局
<RadioGroup
android:id="@+id/radioGroub_listColor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<info.androidhive.slidingmenu.model.ExpandableHeightGridView
android:id="@+id/color_grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="4"
android:scrollbarStyle="outsideOverlay"
android:verticalScrollbarPosition="right"
android:scrollbars="vertical"
android:background="@drawable/bordertop_gridview"
/>
</RadioGroup>