Android PopupWindow & some problems
来源:互联网 发布:第三章数据库设计 编辑:程序博客网 时间:2024/05/19 03:44
1====main.xml.
Define a Show_button
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button android:id="@+id/show_button"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="Show"
/>
</LinearLayout>
2====popupwindow.xml
Define the Content to Popup Window
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="NIhao,woahiaffaafaf!!@@@##"
android:textSize="20sp"
android:textColor="#FF0000"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="30dp"
android:id="@+id/name_edit"
/>
<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:text="Enter Name"
android:id="@+id/name_button"
/>
<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:text="Cancel"
android:id="@+id/cancel_button"
/>
</LinearLayout>
3====MainActivity.java
package com.android.tian;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
Button mShowBtn;
Button mNameBtn;
Button mCancelBtn;
EditText mNameEdit;
View vPopupWindowView;
LayoutInflater inflater;
PopupWindow mPopupWindow;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取控件
mShowBtn = (Button)findViewById(R.id.show_button);
mNameBtn = (Button)findViewById(R.id.name_button);
//响应按钮事件
mShowBtn.setOnClickListener(new ClickEvent());
//??!!mCancelBtn.setOnClickListener(new ClickEvent());
}
public void showPopWindow(Context context,View parent){
inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mCancelBtn = (Button)findViewById(R.id.cancel_button);
mNameEdit=(EditText)findViewById(R.id.name_edit);
//!!mNameBtn.setOnClickListener(new ClickEvent());
mCancelBtn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mPopupWindow.dismiss();
}
});
vPopupWindowView = inflater.inflate(R.layout.popupwindow,null,false);
mPopupWindow = new PopupWindow(vPopupWindowView,300,300,true);
//mPopupWindow.showAtLocation(parent,Gravity.LEFT,0,0);
mPopupWindow.showAsDropDown(parent);
}
//统一处理的按钮事件类
class ClickEvent implements OnClickListener {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if((Button)v==mShowBtn){
showPopWindow(MainActivity.this,MainActivity.this.findViewById(R.id.show_button));
}else if((Button)v==mNameBtn){
mNameEdit = (EditText)MainActivity.this.findViewById(R.id.name_edit);
mNameEdit.setText("What");
}else if((Button)v==mCancelBtn){
mPopupWindow.dismiss();
}
}
}
}
Problems:
为什么出错!!!!
好像是mCancleBtn的响应事件的错误???可我不知道为什么,高手指教!
- Android PopupWindow & some problems
- ubuntu android some problems
- some problems
- some problems
- Some interesting C problems
- Some problems of mysql
- Some Problems of FATFS
- Some Sharepoint problems and resolutions
- Some essential problems in C
- android Problems
- Some unsure problems about JCreator Pro
- Some tricky problems related to "protected"
- some problems in video quality detect
- Java Notes: Some Tricky Problems in Java
- Some Problems About Frame Synchronization Framework
- Android-Popupwindow
- android PopupWindow
- android PopupWindow
- HP笔记本电脑装系统教训与经验
- 师兄空间转来的数据处理方法
- c++ 赋值构造函数 临时变量 临时对象 之一
- 谷歌浏览器chrome使用的几点技巧
- 几种利用SAR获取地面高程信息的方法【转载】
- Android PopupWindow & some problems
- 按指定的列col排序数组A,并保持数组行相对不变
- File,FileInputStream,FileReader,InputStreamReader,BufferedReader
- nsoperationQueue的使用
- As3.0中的数据类型转换
- ubuntu 11 下Text Editor打开中文文本出现乱码的解决办法
- Master Note:'Warning: Subscription For Node Down Event Still Pending' In Listener Log
- C# 泛型 单例
- JSON的数组对象 可以向javascript的Array对象一样操作