OnLongClickListener接口接入
来源:互联网 发布:武工队后勤部淘宝店铺 编辑:程序博客网 时间:2024/05/29 09:05
这里面的代码都是很简单的,所以在这里就简单的说一下
在string.xml中加入如下代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">OnLongClickListener</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="textView">请您长按下面的按钮</string>
<string name="button">请长时间按我</string>
</resources>
其main.xml代码:
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.onlongclicklistener.MainActivity" >
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/textView"
android:textSize="20px"
android:gravity="center" />
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView"
android:layout_below="@+id/textView"
android:text="@string/button" />
</RelativeLayout>
MainActivity代码如下:
package com.example.onlongclicklistener;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnLongClickListener{
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button);
button.setTextSize(20);
button.setOnLongClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onLongClick(View arg0) {
if(arg0==button){
Toast.makeText(this, "长时间按下了按钮", Toast.LENGTH_SHORT).show();
}
return false;
}
}
- OnLongClickListener接口接入
- 安卓 OnLongClickListener接口简介 以及案例
- 付费接口接入
- php接入短信接口
- QQ接口接入
- onLongClickListener使用
- ChinaPay 支付接口接入 案例
- 应用系统接入接口开发
- EIAC.SSO接入接口文档
- 京东接口接入分享
- app接入支付宝接口
- 新浪微博接口接入
- 短信系统外围接入接口
- PHP接入支付宝下单接口
- OnTouchListener、OnClickListener、OnLongClickListener
- OnLongClickListener长按事件
- 使用JMS接口接入WebSphere MQ消息
- 第三方平台接口接入详解
- python datetime详解
- Hibernate基于主键的多对多映射2015-11-11
- 线性表
- 蓝懿iOS 技术内容交流和学习心得 11.11
- PostgreSQL安全指南 - Postgres2015全国用户大会--重磅嘉宾佳作分享(周正中)
- OnLongClickListener接口接入
- c++对象
- 修改FoxitReader (福昕PDF阅读器)最近打开文档数目的上限
- 全面解析Linux 内核 3.10.x - 开始编译<一>
- 0102 混蛋罗心得[敌人方位(多图, 慎入)]
- [Django架构流程分析]了解Django Middleware的几个关键方法
- yii2 安装
- 寄居蟹与海葵
- Struts例子——第一篇