- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
当从单独的类调用 PopupWindow 方法时,我希望能够从 xml 文件定义 PopupWindow 中的布局。下面的代码根据需要工作,除了布局是从 java 文件而不是 xml 文件中提取的。在这种情况下,我不知道如何正确访问 xml 布局并在 PopupWindow 中实现,或者这是否可能。意见和具体建议表示赞赏。谢谢。
showPopup.java
public class showPopup {
Context ctx;
Button btnDismiss;
public showPopup(Context ctx){
this.ctx = ctx;
}
public void onCreateView(LayoutInflater layoutInflater, ViewGroup container) {
View layout = layoutInflater.inflate(R.layout.popup_layout, null);
btnDismiss = (Button) layout.findViewById(R.id.btndismissxml);
}
public void goJoe(View parent){
final PopupWindow popup = new PopupWindow(ctx);
btnDismiss = new Button (ctx);
btnDismiss.setText("Text is from showPopup.java");
popup.setContentView(btnDismiss);
popup.setWidth(400);
popup.setHeight(580);
popup.showAtLocation(parent, Gravity.CENTER_HORIZONTAL, 10, 10);
btnDismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popup.dismiss();
}
});
}
}
Tab3Fragment.java
public class Tab3Fragment extends Fragment implements OnClickListener{
Button btnPopup;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup containerGroup, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab3_fragment, containerGroup, false);
btnPopup = (Button)v.findViewById(R.id.btnPopupxml);
btnPopup.setOnClickListener(this);
return v;
}
//@Override
public void onViewCreated(View v) {
btnPopup = (Button)v.findViewById(R.id.btnPopupxml);
btnPopup.setOnClickListener(this);
}
@Override
public void onClick(View parent) {
new showPopup(getActivity().getApplicationContext()).goJoe(parent);
}
}
popup_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/layout">
<Button android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:id="@+id/btndismissxml"
android:text="Text is from popup_layout.xml"></Button>
</RelativeLayout>
更新(1835 年,12 月 11 日):这是草稿弹出窗口。应用程序中将有几个这样的服务用户可编辑下拉字段。
最佳答案
像这样改变showPopup
public class showPopup {
Context ctx;
Button btnDismiss, btnSaveRecord, btnLastRecord;
EditText edSpeciesLookup,edSpeciesLookupRowid;
DBAdapter msdb;
SQLiteDatabase db;
public showPopup(Context ctx){
this.ctx = ctx;
msdb = new DBAdapter(ctx,"gfda", null);
db = msdb.getWritableDatabase();
}
public void goJoe(View parent){
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popUpView = inflater.inflate(R.layout.popup_layout, null, false);
final PopupWindow popup = new PopupWindow(popUpView, 400,
580, true);
popup.setContentView(popUpView);
btnDismiss = (Button) popUpView.
findViewById(R.id.btndismissxml);
edSpeciesLookup = (EditText) popUpView.
findViewById(R.id.editspecieslookupxml);
edSpeciesLookupRowid = (EditText) popUpView.
findViewById(R.id.editspecieslookuprowidxml);
popup.showAtLocation(parent, Gravity.CENTER_HORIZONTAL, 10, 10);
btnDismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popup.dismiss();
}
});
btnSaveRecord = (Button) popUpView.findViewById(R.id.btnSaveRecordxml);
btnSaveRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {//SAVE
String szSpecies = edSpeciesLookup.getText().toString();
if(szSpecies.matches("")){//checks to see if species field is empty...
///nothing happens...
}else{db.execSQL("INSERT INTO speciesLookupDb (species) VALUES ('"+szSpecies+"')");
resetForm();
}
}
});
btnLastRecord=(Button)popUpView.findViewById(R.id.btnLastRecordxml);
btnLastRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor c = db.rawQuery("SELECT * FROM speciesLookupDb WHERE _id = (SELECT MAX(_id) FROM speciesLookupDb)",null);
if (c.moveToFirst()){////a record exists (table is not blank)
edSpeciesLookupRowid.setText(c.getString(0));
edSpeciesLookup.setText(c.getString(1));
}else{//no record here...table is blank.
}
}
});
}
}
如果你想在触摸屏幕上的任何地方时关闭 popup
那么你必须在弹出的 setContentView
之后和 showAtLocation
之前添加这些行/p>
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.any_drawable);
popup.setBackgroundDrawable(new BitmapDrawable(getResources(),
bitmap));
popup.setOutsideTouchable(true);
popup.setFocusable(true);
关于android - 当从单独的类调用 PopupWindow 方法时,如何从 xml 文件在 PopupWindow 中定义布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27409781/
Java 专家需要您的帮助。 今天我在一次采访中被问到这个问题,但我无法解决。所以我需要一个解决方案来解决这个问题; 反转字符串 Input : Hello, World! Output : oll
目标:单击按钮并将成分作为单独的项目添加到数组中。 当前设置: 这给出:蓝莓芒果柠檬汁 然后我希望能够通过单击按钮将成分作为单独的项目添加到数组中: var allI
如何编写正则表达式来匹配它(参见箭头): "this is a ->'' this is a "test' there is another "test' 第二种情况 /\b'/ Regex Demo
我有一个数组,其中包含有限数量的项目。我想随机删除项目,直到所有项目都被使用过一次。 示例 [1,2,3,4,5] 使用了随机数 5,所以我不想再这样了。使用了随机数 2,所以我不想再这样了。等等..
首先,抱歉,如果这太主观了,我只是不知道还能怎么问/去哪里问。 无论如何,鉴于我最近的所有问题,我准备很快发布一个 Android 应用程序,并且大部分测试都是在我的手机 Droid 上完成的。我真的
这可能不是这个问题的正确位置,如果不合适请随意移动它。我标记为 Delphi/Pascal 因为这是我在 atm 中工作的内容,但这可能适用于我猜的所有编程。 无论如何,我正在做一些代码清理,并考虑将
我像这样分隔了其余 api 的路由。有没有更好的方法来组织路由器?还是我现在的做法没问题? app.js app.use('/api/auth',auth); 应用程序/ Controller /au
我在 2 个单独的工作表中包含以下数据: 表1: A B C D a ff dd ff ee b 12 10 10 12 表2: A B C
我正在使用 jQuery,并在位于单独 HTML 文件中的表中获取了几行。单击时,每一行都会成功重定向到本地 HTML 文件。 (使用window.location) 我想要实现的目标 我想要完成的是
我有重叠背景图像的问题,当它们重叠时会导致阴影比不重叠时更暗,从而产生不均匀的阴影。 我有一个高度灵活的盒子,带有一些透明的背景图像和阴影以创建漂亮的边框。盒子本质上是 3 个元素。 您可以在此处找到
按照正常的微服务框架,我们希望将每个微服务放入其自己的 git 存储库中,然后为 Service Fabric 项目创建一个存储库。当我们更新其中一个微服务时,Service Fabric 项目将仅重
我想将多个片段嵌入到一个指令中。这是我的设置方式。 Everyone Development (3)
我希望在保留原件的同时将多个文件 gzip 到一个目录中(到多个 .gz 文件中)。 我可以使用这些命令来处理单个文件: find . -type f -name "*cache.html" -exe
有没有办法分别知道每个 Eclipse 插件消耗了多少内存? 最佳答案 进行堆转储并使用例如分析它Eclipse Memory Analyser . 如需更多信息,请参阅 Analyzing Equi
我们使用cusrom插件并以这种方式定义脚本(这是一个近似的伪代码): //It is common part for every script (1) environments { "env1"
我在控制台应用程序中托管了一个集线器,并有一个 WPF 应用程序连接到它。它工作得很好。然后我将集线器移到一个单独的项目中,并将主机的引用添加到新项目中。现在我收到 500 错误,没有其他详细信息。
是否可以在单独的 JAR 文件中为 JavaBean 构建类?具体来说,JavaBean 在一个 JAR 文件中具有 Bean 和 BeanInfo 类,而自定义属性编辑器类位于另一个 JAR 文件中
好的,所以我有一个 MAF 应用程序,它在单独的应用程序域中加载每个插件。这非常适合我的需要,因为它允许我在运行时动态卸载和重新加载我的插件。 问题是,我需要能够在子应用域中处理未处理的异常,捕获它,
在参加在线数据库类(class)(针对初学者)时,我注意到一个问题,我必须查找涉及...至少两个不同值的查询...例如, ELMASRI 书中的 COMPANY 数据库指出:查找至少从事两个不同项目的
(首先:我已经尝试了涉及边距、边框等的所有选项。) Link to problematic page. Link to similarly constructed, non-problematic p
我是一名优秀的程序员,十分优秀!