I am having a table layout with eleven rows and five columns on the fifth column i had placed the checkboxes.Each row containing one check box now i want to select all the check box at once by clicking "SELECT ALL" in context menu This is what i had done but wont work for me please help me with this:
public class ckt extends Fragment {
public int []check_box_count = new int[12];
public int [] Table_Row_Count = new int[12];
TableRow table_row;
TableLayout table;
CheckBox check_box,check_box_2;
int i,j;
TextView tv;
View Root_view;
int [] Checked_Count= new int[12];
String[][] str;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Root_view = inflater.inflate(R.layout.manualmode_ac_fuse_ckt, null);
table = (TableLayout)Root_view.findViewById(R.id.table_layout_manual_mode);
Table_Row_Count[0] = R.id.tableRow1_manual;
Table_Row_Count[1] = R.id.tableRow2_manual;
Table_Row_Count[2] = R.id.tableRow3_manual;
Table_Row_Count[3] = R.id.tableRow4_manual;
Table_Row_Count[4] = R.id.tableRow5_manual;
Table_Row_Count[5] = R.id.tableRow6_manual;
Table_Row_Count[6] = R.id.tableRow7_manual;
Table_Row_Count[7] = R.id.tableRow8_manual;
Table_Row_Count[8] = R.id.tableRow9_manual;
Table_Row_Count[9] = R.id.tableRow10_manual;
Table_Row_Count[10] = R.id.tableRow11_manual;
Table_Row_Count[11] = R.id.Table_Row_12;
// table_row = (TableRow)Root_view.findViewById(Table_Row_Count[i]);
check_box_count[0] = R.id.cb_1;
check_box_count[1] = R.id.cb_2;
check_box_count[2] = R.id.cb_3;
check_box_count[3] = R.id.cb_4;
check_box_count[4] = R.id.cb_5;
check_box_count[5] = R.id.cb_6;
check_box_count[6] = R.id.cb_7;
check_box_count[7] = R.id.cb_8;
check_box_count[8] = R.id.cb_9;
check_box_count[9] = R.id.cb_10;
check_box_count[10] = R.id.cb_11;
check_box_count[11] = R.id.cb_12;
// check_box = (CheckBox)Root_view.findViewById(check_box_count[i]);
registerForContextMenu(table);
return Root_view;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("MANUAL MODE : AFTER FUSE CONNECTION");
menu.add(0, v.getId(), 0, "TEST");
menu.add(0, v.getId(), 0, "SELECT ALL");
menu.add(0, v.getId(), 0, "DESELECT ALL");
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="TEST")
{
for(i=0,j=0;i<11;i++)
{
check_box = (CheckBox)Root_view.findViewById(check_box_count[i]);
if(check_box.isChecked()==true)
Checked_Count[j++]=i+1;
}
if(j==0)
Toast.makeText(getActivity(), "Tests not selected", Toast.LENGTH_LONG).show();
else
{
//Perform Operations
}
if(item.getTitle()=="SELECT ALL"){
for(i=0;i<11;i++){
check_box_2 = (CheckBox)Root_view.findViewById(check_box_count[i]);
check_box_2 = (CheckBox)((TableRow)table.getChildAt(i)).getChildAt(4);
}
}
return super.onContextItemSelected(item);
}
}
Aucun commentaire:
Enregistrer un commentaire