我有一个LayoutXML定义,由几个Buttons 组成.
目前我在OnCreate方法中这样做,以针对按钮定义事件处理程序:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button newPicButton = (Button)findViewById(R.id.new_button);
newPicButton.setOnClickListener(btnListener);
..... similarly for other buttons too
.....
}
Run Code Online (Sandbox Code Playgroud)
里面的Button的onClick情况下,我启动相机Intent获取的图片,里面onActivityResult的回调,我再次设置沿设定的事件处理程序View是这样的:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
setContentView(R.layout.main);
Button newPicButton = (Button)findViewById(R.id.new_button);
newPicButton.setOnClickListener(btnListener);
...similarly for other buttons too
}
Run Code Online (Sandbox Code Playgroud)
我是android新手,这种每次重新定义事件的方法对我来说都很脏.我想知道在这样的场景中定义按钮事件处理程序方面的最佳实践是什么.
编辑:粘贴我的完整课程
public class CameraAppActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public …Run Code Online (Sandbox Code Playgroud) 我写了一个Stack and Queue实现(基于Linked List).有一个堆栈(bigStack).例如,我分开bigStack(例如:stackA和stackB).我pop()是一个节点bigStack,我push()在stackA.以同样的方式,我push()在stackB.我想bigStack不要改变.因此我想克隆该bigStack对象.如何在C++中克隆对象?或者我的问题有另一种解决方案吗?
class Stack : public List {
public:
Stack() {}
Stack(const Stack& rhs) {}
Stack& operator=(const Stack& rhs) {};
~Stack() {}
int Top() {
if (head == NULL) {
cout << "Error: The stack is empty." << endl;
return -1;
} else {
return head->nosu;
}
}
void Push(int nosu, string adi, string …Run Code Online (Sandbox Code Playgroud) @Path("/hello")
public class Hello {
@POST
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public JSONObject sayPlainTextHello(@PathParam("id")JSONObject inputJsonObj) {
String input = (String) inputJsonObj.get("input");
String output="The input you sent is :"+input;
JSONObject outputJsonObj = new JSONObject();
outputJsonObj.put("output", output);
return outputJsonObj;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的webservice(我正在使用Jersey API).但我无法找到一种方法从java rest客户端调用此方法来发送和接收json数据.我尝试了以下方式来编写客户端
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
JSONObject inputJsonObj = new JSONObject();
inputJsonObj.put("input", "Value");
System.out.println(service.path("rest").path("hello").accept(MediaType.APPLICATION_JSON).entity(inputJsonObj).post(JSONObject.class,JSONObject.class));
Run Code Online (Sandbox Code Playgroud)
但这显示以下错误
Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.lang.Class, and MIME media …Run Code Online (Sandbox Code Playgroud) 这是我的工作代码示例:
#include <iostream>
template<typename B>
class b {
public:
int y;
constexpr b(int x) : y(x) {
}
constexpr void sayhi() {
std::cout << "hi" << std::endl;
}
};
template<int x>
struct A {
static constexpr b<int> bee = x;
static constexpr int y = x; // this one is fine and usable already, I don't have to do something like what I did on member bee
inline static void sayhi() {
std::cout << y << std::endl;
}
};
template<int …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JDO在GAE中保持一对多拥有双向导航的关系.
我手动添加Contact到User类,我希望最终Contact将有一个对父User对象的引用.
org.datanucleus.store.appengine.DatastoreRelationFieldManager.checkForParentSwitch(DatastoreRelationFieldManager.java:204)User对象持久性之后,父引用不会更新.Contact使用密钥从数据存储区检索对象后,不会更新父引用.我不明白我的错误在哪里.
package test;
import java.util.ArrayList;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.google.appengine.api.datastore.Key;
public class DatastoreJdoTest extends LocalServiceTestCase {
@Autowired
@Qualifier("persistenceManagerFactory")
PersistenceManagerFactory pmf;
@Test
public void testBatchInsert() {
Key contactKey;
PersistenceManager pm = pmf.getPersistenceManager();
try {
pm.currentTransaction().begin();
User user = new User();
Contact contact = …Run Code Online (Sandbox Code Playgroud)