![](/img/trans.png)
[英]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.