Java Parse.com检索数据方法
我正在尝试将以下代码(从云中提取的代码)放入一个方法中Java Parse.com检索数据方法,java,android,Java,Android,我正在尝试将以下代码(从云中提取的代码)放入一个方法中 ParseQuery<ParseObject> query = ParseQuery.getQuery("Parse name"); query.getInBackground("asdlasdKSas2", new GetCallback<ParseObject>() { public void done(ParseObject object, ParseException e) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Parse name");
query.getInBackground("asdlasdKSas2", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
//Cost
shirtCost = (TextView)findViewById(R.id.cost1);
int s1 = object.getInt("cost");
shirtCost.setText(s1);
//Name
shirt = (TextView)findViewById(R.id.snack1);
String s2 = object.getString("item");
shirt.setText(s2);
//Desc
shirtdesc = (TextView)findViewById(R.id.snack1description);
String s3 = object.getString("description");
shirtdesc.setText(s3);
} else {
// something went wrong
}
}
});
ParseQuery query=ParseQuery.getQuery(“解析名称”);
getInBackground(“asdlasdksa2”,新的GetCallback(){
公共无效完成(ParseObject对象,parsee异常){
如果(e==null){
//成本
shirtCost=(TextView)findViewById(R.id.cost1);
int s1=object.getInt(“成本”);
衬衫成本设定值(s1);
//名字
shirt=(TextView)findViewById(R.id.snack1);
strings2=object.getString(“项”);
shirt.setText(s2);
//描述
shirtdesc=(TextView)findViewById(R.id.Snack1说明);
strings3=object.getString(“description”);
shirtdesc.setText(s3);
}否则{
//出了点问题
}
}
});
shirtCost、shirt和shirtDesc都是文本视图。
我希望能够调用一个函数,该函数将用我所说的替换shirt、shirtDesc和shirtCost。以下是我试图做的(没有成功):
public void setData(字符串键、字符串类名、TextView main、TextView成本、TextView描述){
ParseQuery=ParseQuery.getQuery(类名);
getInBackground(键,new GetCallback(){
公共无效完成(ParseObject对象,parsee异常){
如果(e==null){
//成本
成本=(TextView)findViewById(R.id.);
int s1=object.getInt(“成本”);
成本。setText(s1);
//名字
main=(TextView)findViewById(R.id.snack1);
strings2=object.getString(“项”);
main.setText(s2);
//描述
desc=(TextView)findViewById(R.id.);
strings3=object.getString(“description”);
desc.setText(s3);
}否则{
//出了点问题
}
}
});
}
任何建议都会令人惊讶。解决办法会更好。希望我能深入到你能理解的地方。谢谢
我想解释一下。在夏天,这是我不明白的。看看这个方法:
public void example(TextView cost, <permeter idk how to pass. keep reading>) {
cost = (TextView)findViewByID(HOW DO I GET THIS ID THROGUH PERIMETER??);}
public void示例(TextView成本){
cost=(TextView)findViewByID(如何通过周长获取此ID??);}
我需要通过参数传递ID,但我完全不知道。如果要在第二段代码中替换
shirtCost
、shirt
和shirtdesc
中的值,则必须使用与第一段代码相同的EditText
你说:
我希望能够调用一个函数,该函数将用我所说的替换shirt、shirtDesc和shirtCost
因此,对于在第一段代码中使用的每个变量,必须分别使用相同的EditText
。因此,在第二段代码中,您对findViewById
函数的使用必须如下所示:
cost = (TextView)findViewById(R.id.cost1);
main = (TextView)findViewById(R.id.snack1);
desc = (TextView)findViewById(R.id.snack1description);
您必须为每个变量使用相同的EditText,因为您要替换它,因此,您之前在EditText
上设置的文本模糊不清,当您再次为它们设置另一个文本时,之前设置的文本将被您正在设置的第二个文本替换
因此,如果您有:
shirtCost.setText("This is an example");
shirtCost.getText(); //The value will be --> "This is an example"
shirtCost.setText("This text replace the first one");
shirtCost.getText(); //The value will be --> "This text replace the first one"
我希望它会对你有帮助 它到底给了你什么误差?看最后一个参数。Idk如何写参数表@错误404在两个代码中,第13行是注释。我还不太明白你的意思。对不起,我感谢你的帮助和理解。这很难解释。更新了主要帖子。阅读新的底部部分@错误404
shirtCost.setText("This is an example");
shirtCost.getText(); //The value will be --> "This is an example"
shirtCost.setText("This text replace the first one");
shirtCost.getText(); //The value will be --> "This text replace the first one"