0

I am absolutely bigenner in android programming. I have done so far like this..

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scorecard_fragment, container,
            false);

    gridLayout = (GridLayout) view.findViewById(R.id.GridLayout1);

    /*** Default first row */

    gridLayout.setColumnCount(col);
    gridLayout.setRowCount(row);

    if (col == 1) {
        defaultColumn();
    }

    else {

        extendedColumn("");

    }
    return view;
}

public void defaultColumn() {
    // Log.d(TAG, "Default col");

    int i;
    int k = 1;

    for (i = 0; i < 20; i++) {

        if (i == 0)

        {

            ImageView oImageView = new ImageView(getActivity());
            oImageView.setImageResource(R.drawable.ic_player);
            GridLayout.LayoutParams param = new   
  GridLayout.LayoutParams();

            param.setMargins(0, 0, 0, 0);

            gridLayout.addView(oImageView);

        } else if (i < 19) {

            TextView oTextView = new TextView(getActivity());

            oTextView.append("" + (k++) + "\n");
            GridLayout.LayoutParams param = new GridLayout.LayoutParams();
            param.setGravity(Gravity.CENTER);
            param.setMargins(15, 15, 15, 15);
            oTextView.setLayoutParams(param);
            gridLayout.addView(oTextView);

        } else {

            TextView oTextView = new TextView(getActivity());

            oTextView.append("\n");
            GridLayout.LayoutParams param = new GridLayout.LayoutParams();
            param.setGravity(Gravity.CENTER);
            param.setMargins(15, 15, 15, 15);
            oTextView.setLayoutParams(param);
            gridLayout.addView(oTextView);

        }

    }
    col++;

}

public void extendedColumn(String str) {

    Log.d("", "value c1" + col);

    int i;

    for (i = 0; i < 20; i++) {

        if (i == 0)

        {

            TextView oTextView = new TextView(getActivity());
            oTextView.setText(str);
            gridLayout.addView(oTextView);
            // oTextView.setBackgroundResource(R.drawable.border);
            oTextView.setTextSize(14);

        }

        else if (i < 19) {

            Log.d("Implement spinner", "sdfsdfsdf");

            final Spinner s1 = new Spinner(getActivity());

            final ArrayAdapter<CharSequence> adapter = ArrayAdapter
                    .createFromResource(getActivity(), R.array.score_array,
                            android.R.layout.simple_spinner_item);

            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            s1.setAdapter(adapter);
            s1.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {

                    updateResult();

                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {

                }
            });

            gridLayout.addView(s1);

        }

        else {
            TextView oTextView = new TextView(getActivity());

            oTextView.append("\n");
            GridLayout.LayoutParams param = new GridLayout.LayoutParams();
            param.setGravity(Gravity.CENTER);
            param.setMargins(15, 15, 15, 15);
            oTextView.setLayoutParams(param);
            gridLayout.addView(oTextView);

        }
    }
    col++;

}

public void updateResult() {

    int j = gridLayout.getColumnCount();

    Log.d(" Column count", "" + j);

    int k = gridLayout.getRowCount();

    Log.d(" Row count", "" + k);

}

As you can see I am trying get the value from spinner and its current row and column value. I can do that using gridLayout.getColumnCount() and gridLayout.getRowCount(). But that gives me always the total column and row depend on how many user I have. But I want to get the specific row and column no matter how many user I have so that I can calculate my result by knowing which row and column has been selected by which user..Helps or suggestion will be highly appreciated.

1 Answer 1

0

so that I can calculate my result by knowing which value has been selected

To only know the selected value, just implement the onItemClick() method, and inside you will have position of selected value, the view, the parent ViewGroup, etc ...

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.