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();
                }   

我有带有切换按钮的gridview图像。如果我单击“打开”位置的切换按钮,那么如果我单击android中的更新按钮,如何获得“打开”位置的单击位置总数?

4

0 回答 0