I am having table layout with twelve table rows and having 12 check boxes that is one in each row. I want to retrieve the selected check box row values even if I had select multiple check boxes also this is what I had done but wont work for me please help me
package com.developer.android;
import java.util.Arrays;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import com.material.widget.CheckBox;
public class Manual_AC_Fuse_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;
int i;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View Root_view = inflater.inflate(R.layout.manualmode_ac_fuse_ckt, null);
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_row);
table_row.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
for(int i=0;i<check_box.length();i++){
if(check_box.isChecked()==true){
int count = table_row.getChildCount();
String[] str = new String[count];
for(int j=0;j<count;j++){
TextView tv = (TextView)(((TableRow)table_row)).getChildAt(i);
str[j] = tv.getText().toString();
}
Toast.makeText(getActivity(), Arrays.toString(str), Toast.LENGTH_LONG).show();
}
}
return true;
}
});
return Root_view;
}
}