2
public class MainActivity extends Activity {

    String[] countries = new String[] {
            "India",
            "Pakistan",
            "Sri Lanka",
            "China",
            "Bangladesh",
            "Nepal",
            "Afghanistan",
            "North Korea",
            "South Korea",
            "Japan"
        };


    // Array of booleans to store toggle button status
    boolean[] status = {
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false
    };

int v1;
    ArrayList<Integer> intItems = new ArrayList<Integer>();

    int pos;
    String sta;


Button updatespot=(Button) findViewById(R.id.update);
            updatespot.setOnClickListener(new View.OnClickListener() {           //abre setonclicklistener(
                 @Override
                 public void onClick(View v) {
    //               final

                    if(sta == "On" )        
                        {
                            intItems.add(v1);
           Toast.makeText(getBaseContext(),  "position : " + intItems, Toast.LENGTH_SHORT).show();



                 }

                 }
            });

            GridView lvCountries = (GridView) findViewById(R.id.lv_countries);

            OnItemClickListener itemClickListener = new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> lv, View item, int position, long id) {

                    GridView lView = (GridView) lv;

                    SimpleAdapter adapter = (SimpleAdapter) lView.getAdapter();

                    HashMap<String,Object> hm = (HashMap) adapter.getItem(position);

                    /** The clicked Item in the GridView */
                    FrameLayout rLayout = (FrameLayout) item;

                    /** Getting the toggle button corresponding to the clicked item */
                    ToggleButton tgl = (ToggleButton) rLayout.getChildAt(1);

                    String strStatus = "";
                    if(tgl.isChecked()){
                        tgl.setChecked(false);
                        strStatus = "Off";
                        status[position]=false;
                    }else{
                        tgl.setChecked(true);
                        strStatus = "On";
                         sta=strStatus;

                        status[position]=true;  


                         v1=position;

          //  Toast.makeText(getBaseContext(), (String) hm.get("txt") + " : " + v1, Toast.LENGTH_SHORT).show();
                }   

「オン」の位置でトグルボタンをクリックすると、アンドロイドで更新ボタンをクリックすると、「オン」の位置でクリックされた位置の総数を取得するにはどうすればよいですか?

4

0 に答える 0