基本信息
源码名称:zigbee局域网控制灯打开关闭
源码大小:0.08M
文件格式:.zip
开发语言:Java
更新时间:2018-12-11
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package my.com.test; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.gsm.SmsManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.GridView; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; public class Control extends Activity { private Button mButton1; private EditText mEditText1; private GridItemAdapter adapter; private GridView mygridview; //private Button on; //private Button off; //public List<MyGrid> list; private String[] titles=new String[]{"灯1","灯2","灯3","灯4","灯5","灯6","灯7","灯8","灯9","灯10","灯11","灯12","灯13","灯14","灯15","灯16",}; private int[]images={R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff, R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff,R.drawable.loff, R.drawable.loff,R.drawable.loff,}; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.grid); mEditText1=(EditText)findViewById(R.id.editText1); mButton1=(Button)findViewById(R.id.button1); mButton1.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v) { String messageAddress = mEditText1.getText().toString(); String messageContent = "check"; SmsManager smsManager = SmsManager.getDefault(); if(messageAddress.trim().length()!=0 && messageContent.trim().length()!=0) { try{ PendingIntent pintent = PendingIntent.getBroadcast(Control.this, 0, new Intent(), 0); smsManager.sendTextMessage(messageAddress, null, messageContent, pintent, null); }catch(Exception e) { e.printStackTrace(); } Toast.makeText(Control.this, "发送成功", Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(Control.this, "发送地址或者内容不能为空", Toast.LENGTH_SHORT).show(); } } }); mygridview=(GridView)findViewById(R.id.gridview); //寻找资源,在main中的GridView adapter=new GridItemAdapter(titles,images,this); mygridview.setAdapter(adapter); mygridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v,int position,long i) //The AdapterView where the click happened //The view within the AdapterView that was clicked //The position of the view in the adapter //The row id of the item that was clicked { GridView changedgridview=(GridView)findViewById(R.id.gridview); if(images[position]==R.drawable.loff) { images[position]=R.drawable.lon2; GridItemAdapter changedadapter=new GridItemAdapter(titles,images,Control.this); changedgridview.setAdapter(changedadapter); Toast.makeText(Control.this, "灯" (position 1) "已经打开", Toast.LENGTH_SHORT).show(); } else { images[position]=R.drawable.loff; GridItemAdapter changedadapter=new GridItemAdapter(titles,images,Control.this); changedgridview.setAdapter(changedadapter); Toast.makeText(Control.this, "灯" (position 1) "已经关闭", Toast.LENGTH_SHORT).show(); } } }); } public class MyGrid { private String title; private int imageId; public MyGrid(String objname,int imageId) { super(); this.title=objname; this.imageId=imageId; } public String getObjname() { return title; } public int getImageId() { return imageId; } } public class GridItemAdapter extends BaseAdapter { private List<MyGrid> gridlist; private LayoutInflater inflater; public GridItemAdapter(String[] Objname,int[]images,Context context) { super(); gridlist=new ArrayList<MyGrid>(); inflater=LayoutInflater.from(context); for(int i=0;i<images.length;i ) { MyGrid picture=new MyGrid(Objname[i],images[i]); gridlist.add(picture); } } public int getCount() { return gridlist.size(); } public long getItemId(int index) { return index; } public Object getItem(int index) { return gridlist.get(index); } public class ViewHolder { ImageView image; TextView text; } public View getView(int index,View view,ViewGroup parent) { ViewHolder gridholder; if(view==null) { view=inflater.inflate(R.layout.control, null); gridholder=new ViewHolder(); gridholder.image=(ImageView)view.findViewById(R.id.gridimageview); gridholder.text=(TextView)view.findViewById(R.id.gridtextview); view.setTag(gridholder); } else { gridholder=(ViewHolder)view.getTag(); } gridholder.image.setImageResource(gridlist.get(index).getImageId()); gridholder.text.setText(gridlist.get(index).getObjname()); return view; } } }