setOnLongClickListener setWallPaper
2014-06-12 23:54
246 查看
.java文件
package com.example.setwallpaper_e; import java.io.IOException; import android.os.Bundle; import android.app.Activity; import android.content.res.Resources.NotFoundException; import android.view.Menu; import android.view.View; import android.view.View.OnLongClickListener; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView iv=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv=(ImageView) this.findViewById(R.id.iv_info); MainActivity.this.iv.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { // TODO Auto-generated method stub try { MainActivity.this.clearWallpaper(); MainActivity.this.setWallpaper(MainActivity.this.iv.getResources().openRawResource(R.drawable.beauty_2)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
.xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ImageView android:id="@+id/iv_info" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/beauty" /> </LinearLayout>
相关文章推荐
- Android setOnLongClickListener()使用笔记
- setOnLongClickListener 返回值的作用
- Android setOnLongClickListener return
- ListView、ListFragment 无法实现 onListItemClick和setOnLongClickListener
- android onClickListener onLongClickListener事件冲突
- android lsitview setOnItemLongClickListener 无效或不执行
- Android-PullToRefresh 下拉刷新增加setOnItemLongClickListener
- android OnLongClickListener长按事件返回值
- 为什么ListView.setOnItemClickListener、setOnCreateContextMenuListener会无效为什么ListView.setOnItemClickListen
- OnTouchListener、OnClickListener、OnLongClickListener
- 为什么ListView.setOnItemClickListener、setOnCreateContextMenuListener会无效
- android应用中常用的监听OnTouchListener、OnClickListener、OnLongClickListener
- setOnItemSelectedListener、setOnItemClickListener与setOnTouchlistener的区别
- Android setOnItemLongClickListener setOnItemClickListener 同时触发解决
- Android API 中文(76)——AdapterView.OnItemLongClickListener
- setOnItemSelectedListener、setOnItemClickListener与setOnTouchlistener的区别
- listview长按事件setOnItemLongClickListener的用法
- 解决ListView setOnItemLongClickListener 长按无响应(嵌套GridView)
- 为什么ListView.setOnItemClickListener、setOnCreateContextMenuListener会无效为什么ListView.setOnItemClickListen
- 关于ExpandableListView.setOnChildClickListener获取不到点击事件