[英]Android SetText not working on TextVIew but the value is there
[英]Android setText not working on TextView
我试图改变一个TextView一些资料我查询解析为的价值,但由于某些原因, .setText
未服用影响。
我尝试了谷歌搜索,但.getString
也不起作用。 我对解析任何建议还很陌生?
我的代码如下:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import org.w3c.dom.Text;
import java.util.List;
/**
* A simple {@link Fragment} subclass.
*/
public class productDetail extends Fragment {
public productDetail() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View theView = inflater.inflate(R.layout.fragment_product_detail, container, false);
final TextView productNameLabel = (TextView) theView.findViewById(R.id.productNameTextView);
final TextView productDetailsLabel = (TextView) theView.findViewById(R.id.productDetails);
final TextView shippingFeeLabel = (TextView) theView.findViewById(R.id.shippingFee);
final TextView productPriceLabel = (TextView) theView.findViewById(R.id.productPrice);
final TextView productNumberOfReviewsLabel = (TextView) theView.findViewById(R.id.productNumberOfReviews);
final String chosenProduct = getArguments().getString("productName");
Log.i("AppInfo", chosenProduct);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Inventory");
query.whereEqualTo("productName", chosenProduct);
query.getFirstInBackground(new GetCallback<ParseObject>() {
@Override
public void done(ParseObject parseObject, ParseException e) {
if (parseObject == null) {
Integer fee = parseObject.getInt("ShippingFee");
Integer review = parseObject.getInt("numberOfReviews");
String information = parseObject.get("information").toString();
Integer price = parseObject.getInt("price");
productNameLabel.setText(chosenProduct);
productDetailsLabel.setText(String.valueOf(information));
shippingFeeLabel.setText(String.valueOf(fee));
productPriceLabel.setText(String.valueOf(price));
productNumberOfReviewsLabel.setText(String.valueOf(entries));
}
}
});
// Inflate the layout for this fragment
return theView;
}
}
如果输入if语句中的所有内容,它将抛出NullPointerException :)
将if语句更改为此
if (parseObject != null)
也许你是这个意思?
if (e == null)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.