我正在尝试从Api获取JSON对象并将其显示在LinearLayout上的checkList上。即使我将清单View添加到容器中,它也没有显示。是否必须使用notifyDataSetChanged()
,如果是这样,我如何在LinearLayout中实现它。
谢谢。我为我的英语道歉。
public class NasilYapilir extends Fragment {
int index;
private CheckBox checkBox;
private CheckBox[] checkBoxes;
List<Reciep> reciepList = new ArrayList<>();
LinearLayout linearLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_nasil_yapilir, container, false);
index = getArguments().getInt(DetailViewPager.KEY_INDEX_TAG);
load_data(index);
linearLayout = (LinearLayout) view.findViewById(R.id.linearLayout);
checkBoxes = new CheckBox[reciepList.size()];
populateDirections(reciepList,linearLayout);
Log.i("we are in nasil yaplir",index + "");
return view;
}
public void populateDirections(List<Reciep> reciep, ViewGroup container){
int i = 0;
for(Reciep recieps : reciep){
checkBoxes[i] = new CheckBox(getActivity());
// checkBoxes[i].setPadding(8,16,8,16);
checkBoxes[i].setText(recieps.getQuantity()+ " "+ recieps.getUnit_ad()+ " "+ recieps.getIngredients_ad());
reciep.size();
container.addView(checkBoxes[i]);
i++;
}
}
public void load_data(int index) {
task.execute("http://yemekapp.kuarkdijital.com.tr/v_recipe.php?id=" + index);
}
AsyncTask<String, Void, String> task = new AsyncTask<String, Void, String>() {
@Override
protected String doInBackground(String... params) {
URL url;
HttpURLConnection URLConnection = null;
String current = "";
try {
url = new URL(params[0]);
URLConnection = (HttpURLConnection) url.openConnection();
URLConnection.connect();
InputStream inputStream = URLConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
int data = reader.read();
while (data != -1) {
current += (char) data;
data = reader.read();
}
JSONObject itemObject = null;
JSONObject quantityObject = null;
// JSONObject popularObject = null;
JSONObject jsonObject = new JSONObject(current);
String item = jsonObject.getString("item");
JSONArray itemArray = new JSONArray(item);
// JSONArray popularArray = new JSONArray(popular);
for (int i = 0; i < itemArray.length(); i++) {
itemObject = itemArray.getJSONObject(i);
String itemsQuantity = itemObject.getString("items");
JSONArray quantityArray = new JSONArray(itemsQuantity);
for(int j = 0; j<quantityArray.length() ;j++){
quantityObject = quantityArray.getJSONObject(i);
Reciep reciep = new Reciep(quantityObject.getString("Quantity"),quantityObject.getString("unit_ad"),quantityObject.getString("ingredient_ad"));
reciepList.add(reciep);
Log.i("quatityArray",quantityArray.get(j).toString());
}
// popularObject = popularArray.getJSONObject(i);
// DailyData DailyData = new DailyData(dailyObject.getInt("id"), dailyObject.getString("Servings"), dailyObject.getString("Title"), dailyObject.getString("CookTime"), dailyObject.getString("Image"));
// DailyData PopularData = new DailyData(popularObject.getInt("id"), popularObject.getString("Servings"), popularObject.getString("Title"), popularObject.getString("CookTime"), popularObject.getString("Image"));
// daily_data_list.add(DailyData);
// popular_data_list.add(PopularData);
}
}
catch (JSONException e) {
e.printStackTrace();
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return current;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
// notifyDataSetChanged();
}
};
}
答案 0 :(得分:0)
试试此代码
Sub MinimizeDiff()
SolverReset
SolverOk SetCell:="$K$3", MaxMinVal:=2, ByChange:="$C$3:$E$3", Engine:=3
SolverAdd CellRef:="$K$3", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$C$3", Relation:=1, FormulaText:="$F$3"
SolverAdd CellRef:="$D$3", Relation:=1, FormulaText:="$F$3"
SolverAdd CellRef:="$E$3", Relation:=1, FormulaText:="$F$3"
SolverAdd CellRef:="$C$3:$E$3", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$C$3:$E$3", Relation:=3, FormulaText:="0"
SolverOptions MaxTime:=240, Iterations:=100, Precision:=0.000001, AssumeLinear:=False, StepThru:=False, _
Estimates:=2, Derivatives:=1, SearchOption:=1, IntTolerance:=0, Scaling:=False, Convergence:=0.01, _
AssumeNonNeg:=True, MaxTimeNoImp:=30
SolverSolve
End Sub