PopupWindow和Fragment的使用
来源:互联网 发布:调漆配方软件 编辑:程序博客网 时间:2024/05/22 15:43
关键代码
package com.zklz.pop;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
/**
* 如果使用V4包 需呀继承FragmentActivity 获取管理器:getSupportFragmentManager()
*
* 获取Fragment的上下文就是getActivity
*
* @author Administrator
*
*/
public class MainActivity extends Activity implements OnClickListener {
private Button btn;
private FragmentManager manager = getFragmentManager();
private FragmentTransaction ft;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
}
public void onClick(View v) {
View view = View.inflate(this, R.layout.pop_list_item, null);
final PopupWindow popupWindow = new PopupWindow(view,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, true);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
RelativeLayout one = (RelativeLayout) view.findViewById(R.id.one);
RelativeLayout two = (RelativeLayout) view.findViewById(R.id.two);
RelativeLayout three = (RelativeLayout) view.findViewById(R.id.three);
one.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
OneFragment one = new OneFragment();
ft = manager.beginTransaction();
ft.replace(R.id.comment, one);
ft.commit();
popupWindow.dismiss();
}
});
two.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
TwoFragment two = new TwoFragment();
ft = manager.beginTransaction();
ft.replace(R.id.comment, two);
ft.commit();
popupWindow.dismiss();
}
});
three.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ThreeFragment three = new ThreeFragment();
ft = manager.beginTransaction();
ft.replace(R.id.comment, three);
ft.commit();
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(v);
}
}
- PopupWindow和Fragment的使用
- popupWindow的使用和注意事项
- toolbar和popupwindow的使用
- PopupWindow和AlertDialog的使用和区别
- Android的Dialog和PopupWindow的使用
- android:PopupWindow的使用场景和注意事项
- android:PopupWindow的使用场景和注意事项
- Android PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- 弹窗PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- Android PopupWindow的使用和分析
- MacVim
- 队列类模板的使用
- Git 版本管理工具(一)
- 微信公众号资料整理
- java比较Equals和==的区别
- PopupWindow和Fragment的使用
- 正则表达式匹配所有以小写字符开头的单词
- CMM等级
- MACHINE LEARNING IN ACTION KNN
- 软工:CMMI
- Java 并发之 CountDownLatch、CyclicBarrier 和 Semaphore
- android事件分发教程(一):View
- JSON
- android提醒事件