我现在听到很多关于Spring Framework的内容.为什么业界的Spring Framework有这么多的讨论?
以下代码段的作用是什么?为什么要使用Evict?
private void DoEvict(customer cust)
{
AddressRepository.Evict(cust.Address);
cust.Address = AddressRepository.Get(cust.Address.Id);
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个带有注销选项的android应用程序onCreateOptionsMenu.Logout工作正常,但是当我再次按下后退按钮时,它会将我带到上一个活动,当它获得空值时,它会重定向到登录屏幕.现在我的登录屏幕一次又一次出现.当我按下后退按钮但我不知道如何完全关闭应用程序.
这是我在登录屏幕中处理后退按钮的代码:
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("BidNEMO")
.setMessage("Are you sure you want to exit?")
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Main.super.onBackPressed();
finish();
}
}).create().show();
}
Run Code Online (Sandbox Code Playgroud)
请帮帮你..
我正在使用Simple XML库来处理Android应用程序中的XML文件.这些文件可以变得非常大 - 大约1Mb,并且可以非常深入地嵌套,因此它们相当复杂.
当应用程序通过Simple API加载其中一个文件时,最多可能需要30秒才能完成.目前我正在将FileInputStream传递给Simple的Persister类的[read(Class,InputStream)] [2]方法.实际上,它只读取XML节点并将数据映射到模型对象的实例,从而在内存中复制XML树结构.
我的问题是如何改善Android的性能?我目前的想法是将文件的内容读入字节数组,并将ByteArrayInputStream传递给Persister的read方法.我想处理文件的时间会更快,但我不确定节省的时间是否会被首先读取整个文件所花费的时间所抵消.内存限制也可能是一个问题.
这是傻瓜差事吗?在这种情况下,我还能做些什么来提高性能吗?如果不是,我将不得不求助于改进用户对加载文件的进度的反馈.
一些警告:
1)我无法更改我正在使用的XML库 - 有问题的代码是在桌面,移动和Web应用程序中使用的"引擎"的一部分.改变它的开销对于时间来说太过分了.
2)数据文件由用户创建,因此我无法控制嵌套的大小/深度.
我在JUnit测试中有以下代码,这似乎在上周工作失败了本周:
Calendar cal = Calendar.getInstance();
cal.set(2011, Calendar.JULY, 12);
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); // push the date to 15
System.out.println(cal.get(Calendar.DATE));
Run Code Online (Sandbox Code Playgroud)
正如您可能从我的评论中推断出的那样,因为12日是星期二,所以在将DAY_OF_WEEK设置为星期五后,我预计日期为15.但是,打印的值为22,导致测试失败.
但是,如果我按如下方式更改代码,并添加一个额外的调用来获取:
Calendar cal = Calendar.getInstance();
cal.set(2011, Calendar.JULY, 12);
System.out.println(cal.get(Calendar.DATE));
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); // push the date to 15
System.out.println(cal.get(Calendar.DATE));
Run Code Online (Sandbox Code Playgroud)
我得到了我期望的输出,12和15.
有人可以解释一下发生了什么,为什么这个测试上周有效?
如何@在Android XML文件中使用as文本,因为它具有特殊含义?我有一个TextView只会保留文本@
我试过了:
<TextView
android:id="@+id/at_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/account_name"
android:gravity="center_horizontal"
android:padding="3dip"
android:text="@" />
Run Code Online (Sandbox Code Playgroud)
那当然不适用于错误
错误:错误:未指定资源类型(在'text'处,值为'@').
所以我尝试将它指向这样的条目strings.xml:
<string name="at">@</string>这显示错误:
错误:错误:未指定资源类型(在'at'处,值为'@').
那么我如何@作为TextView的文本进行转义?
我有一个具有以下结构的表:
CREATE TABLE `geo_ip` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`start_ip` int(10) unsigned NOT NULL,
`end_ip` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `start_ip` (`start_ip`),
KEY `end_ip` (`end_ip`),
KEY `start_end` (`start_ip`,`end_ip`),
KEY `end_start` (`end_ip`,`start_ip`)) ENGINE=InnoDB;
Run Code Online (Sandbox Code Playgroud)
MySQL的似乎是无法使用我的大多数查询的指标,作为where第一个使用between落在介于start_ip和end_ip:
select * from geo_ip where 2393196360 between start_ip and end_ip;
+----+-------------+--------+------+-------------------------------------+------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+-------------------------------------+------+---------+------+---------+-------------+
| 1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用多选项创建AlertDialog.我试过了,setMultiChoiceItems但我拥有的是一个ArrayList<Category>而不是CharSequence我尝试使用适配器.
问题setAdapter是,当我选择一个项目时,它会关闭对话框窗口.我想要的是选择项目,然后点击确定按钮,看看哪些项目被选中.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
ArrayAdapter<Category> catsAdapter = new ArrayAdapter<Category>(this, android.R.layout.select_dialog_multichoice,this.categories);
builder.setAdapter(catsAdapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
}
});
builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do something
}
});;
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud) android android-arrayadapter multiple-choice android-alertdialog
我们在Tomcat 6上运行了Tapestry-Spring-Hibernate webapp,每秒处理几千个请求.随机地,没有明显的原因,页面只是在浏览器上显示一堆随机字符.但是,刷新页面时,它显示正常.以下是Chrome上乱码页面来源的屏幕截图:

这是我到目前为止所发现的:
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>我的问题是,有人之前遇到过这种情况,如果有的话,他们能指出我应该开始寻找的地方吗?这是一个问题,页面有不正确的内容类型或服务器由于某种原因无法处理它?或者这可能是Tapestry或应用程序本身的框架错误?任何指针都是受欢迎的.此时,我不确定问题出在哪里,所以我不确定这是在ServerFault上还是留在这里.
我有一个ListView,它可以长按其中一个元素创建一个ContextMenu.如何找到在创建此上下文菜单的ListView中选择的元素(而不是选定的MenuItem)?这是我的代码:
list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, final View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Actions");
android.view.MenuItem remove = menu.add("Remove");
final int selectedItem = ((ListView)v).getSelectedItemPosition();
remove.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(android.view.MenuItem item) {
doSomething(listAdapter.getItem(selectedItem)); // NPE here
return true;
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
请注意,我不想要从上下文菜单中选择的项目,而是需要触发此上下文菜单的ListView项目.
我有一个具有多个组的ExpandableList,每个组包含一个不同类型(不同布局)的子级。我有几个结构相似但子视图不同的Activity,因此我决定为其编写一个自定义适配器。适配器在大多数情况下都运行良好,除了以下两个问题:
这是屏幕截图:

这是我的适配器的代码:
public class GenericExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private String[] groups;
private View[] children;
public static interface ExpandableListItemClickListener {
public void onClick(View view, int groupId, int itemId);
}
public GenericExpandableListAdapter(Context context, String[] groups, int[] children) {
if(groups.length != children.length) {
throw new IllegalArgumentException("Items must have the same length as groups.");
}
this.context = context;
this.groups = groups;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.children = new View[children.length];
for(int i = 0; i < children.length; i++) …Run Code Online (Sandbox Code Playgroud) 假设我在应用程序中有以下类:
一个基类:
public abstract class Animal {}
Run Code Online (Sandbox Code Playgroud)
一个子类
public class Dog extends Animal {
public void bark() {
System.out.println("woof");
}
}
Run Code Online (Sandbox Code Playgroud)
来自第三方库的类:
public class ThirdPartyLibrary /* *cough* Hibernate *cough* */{
public List find() {
return new ArrayList() {
// fetched from the db in the actual app of course
{
add(new Dog());
add(new Dog());
add(new Dog());
}
};
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个实用程序类:
public class Util {
public <E extends Animal> E findUnique(List<E> animals) {
return animals.isEmpty() ? null : animals.get(0);
} …Run Code Online (Sandbox Code Playgroud)