91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

添加功能圖標在首頁顯示

發布時間:2020-08-14 18:17:34 來源:網絡 閱讀:369 作者:鷺明 欄目:開發技術

添加功能圖標在首頁顯示




主類:


public class MainActivity extends AppCompatActivity

{

    private List<MyData> mList =new ArrayList<MyData>();

    private SharedPreferences sp;

    private MyAdapter myAdapter;







    @Override

    protected void onCreate ( Bundle savedInstanceState )

    {

        super.onCreate ( savedInstanceState );

        setContentView ( R.layout.activity_main );

        initListView ( );

        initData();


    }




    //上下文菜單

    @Override

    public void onCreateContextMenu ( ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo )

    {

        menu.add ( "刪除" );


    }





    @Override

    public boolean onContextItemSelected ( MenuItem item )

    {


        AdapterView.AdapterContextMenuInfo menuInfo = ( AdapterView.AdapterContextMenuInfo ) item.getMenuInfo ( );

        int position = menuInfo.position;

        MyData myData = mList.get ( position );

        String name = myData.getName ( );

        mList.remove ( position );

        SharedPreferences.Editor edit = sp.edit ( );

        edit.putInt ( name, 0);

        edit.commit ();

        myAdapter.notifyDataSetChanged ();

        return true;


    }




    private void initData ( )

    {


        sp =  getSharedPreferences("data",0);

        mList.clear ();

        for (int i=0;i<Constant.TT.length;i++)

        {


            int anInt = sp.getInt ("0"+i,0 );

            if(anInt!=0)

            {


                mList.add ( new MyData ("0"+i,anInt ) );

            }

        }

        myAdapter.notifyDataSetChanged ();


    }




    private void initListView ( )

    {

        ListView mListView = ( ListView ) findViewById ( R.id.lv );

        myAdapter =  new MyAdapter();

        mListView.setAdapter ( myAdapter );

        registerForContextMenu (mListView);


    }


    




    class MyAdapter extends BaseAdapter

    {





        @Override

        public int getCount ( )

        {

            return mList.size ();

        }


        @Override

        public Object getItem ( int position )

        {

            return null;

        }


        @Override

        public long getItemId ( int position )

        {

            return 0;

        }


        @SuppressLint ( "ViewHolder" )

        @Override

        public View getView ( int position, View convertView, ViewGroup parent )

        {


            View layout = getLayoutInflater ( ).inflate ( R.layout.mainlistview, null );


            ImageView img = ( ImageView ) layout.findViewById ( R.id.mlv_img );

            TextView tv = ( TextView ) layout.findViewById ( R.id.mlv_tv );

            if(mList.size ()>position)

            {


                MyData mydata = mList.get ( position );

                int imgId=mydata.getImgId ();

                if ( imgId!= 0)

                {


                    img.setVisibility ( View.VISIBLE );

                    tv.setVisibility ( View.VISIBLE );

                    img.setImageResource (  imgId );

                    tv.setText ( mydata.getName () );

                }else

                {

                    img.setVisibility ( View.GONE );

                    tv.setVisibility ( View.GONE );

                }


            }




            return layout;

        }


    }





    @Override

    protected void onActivityResult ( int requestCode, int resultCode, Intent data )

    {



        initData();

        super.onActivityResult ( requestCode, resultCode, data );



    }




    public void btnClick ( View v )

    {

        Intent intent = new Intent ( this, SecondActivity.class );

        startActivityForResult ( intent, Constant.requestCode );

    }



}


接口:

interface Constant

{

    public final static int requestCode=01;


    public final static int[] TT={R.drawable.w1,R.drawable.w2,R.drawable.w3,

            R.drawable.w4,R.drawable.w5, R.drawable.w6,

            R.drawable.w7,R.drawable.w8,R.drawable.w9,

            R.drawable.w10, R.drawable.w11};


    public final static String[] SS={"01","02","03","04","05","06","07","08","09","10","11"};


}


添加功能界面類:

public class SecondActivity extends AppCompatActivity

{



    private SharedPreferences sp;


    @Override

    protected void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_second);

        initGridView();


    }


    //找GridView控件

    private void initGridView ( )

    {


         sp =  getSharedPreferences ( "data", 0 );

        GridView gv = ( GridView ) findViewById ( R.id.second_gv );

        MyGridAdapter myGridAdapter = new MyGridAdapter();

        gv.setAdapter ( myGridAdapter );



    }



    class MyGridAdapter extends BaseAdapter

    {


        @Override

        public int getCount ( )

        {


            return Constant.TT.length;

        }


        @Override

        public Object getItem ( int position )

        {


            return null;

        }


        @Override

        public long getItemId ( int position )

        {


            return 0;

        }


        @SuppressLint ( "ViewHolder" )

        @Override

        public View getView ( final int position, View convertView, ViewGroup parent )

        {



            View layout = getLayoutInflater ().inflate ( R.layout.secondgridview,null );

            ImageView img = ( ImageView ) layout.findViewById ( R.id.sgv_img );

            CheckBox cb = ( CheckBox ) layout.findViewById ( R.id.sgv_cb );

            img.setImageResource ( Constant.TT[position] );

            final int p=position;

            cb.setOnClickListener ( new View.OnClickListener ( )

            {

                @Override

                public void onClick ( View v )

                {


                    SharedPreferences.Editor edit = sp.edit ( );

                    edit.putInt ( "0"+p ,Constant.TT[p]);

                    edit.commit ();


                }

            } );


            return layout;

        }



    }



    //返回首頁頁面

    public void btnBack(View v)

    {


        Intent intent = new Intent ( );

        setResult ( Constant.requestCode,intent );

        finish ();


    }


}



數據保存對象類:

public class MyData

{

    private String name;

    private int imgId;



    public MyData ( String name , int imgId )

    {



        this.name = name;

        this.imgId = imgId;

    }



    public String getName ( )

    {


        return name;

    }



    public int getImgId ( )

    {


        return imgId;

    }


    public void setName ( String name )

    {


        this.name = name;

    }



    public void setImgId ( int imgId )

    {


        this.imgId = imgId;

    }

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

阳春市| 大冶市| 同江市| 翁牛特旗| 玉龙| 呼伦贝尔市| 富宁县| 兴义市| 宜川县| 资溪县| 江阴市| 聂拉木县| 陆丰市| 昌吉市| 来凤县| 和静县| 瑞金市| 邵阳市| 拉萨市| 平江县| 上林县| 雷州市| 噶尔县| 丹巴县| 施秉县| 永州市| 长乐市| 鹤峰县| 呼玛县| 平和县| 扬州市| 买车| 琼海市| 青州市| 宁海县| 香河县| 岳普湖县| 普洱| 枣庄市| 东丽区| 汕尾市|