안드로이드 개발 질문/답변
(글 수 45,052)
checkbox( MyIngredientAdapter에 있음)에서 체크된항목과
http://appserver.jbnu.ac.kr/dbfood/viewbasicdatajson.php 의 ingre 항목과 비교해서 체크된 항목과 모두같거나, 각각이 같으면 리스트뷰로 나타내려하는데 ( 여기서 ingre가 공백이아닌 *로 구분되어짐) 어떻게 비교해야하나요?
파싱부분(로그를 찍어보려는데 로그조차 안나오네요ㅜ
try{ JSONArray jabasic = new JSONArray(((String)msg.obj).replace("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">", "")); for(int i=0; i<jabasic.length(); i++){JSONObject orderbasic = jabasic.getJSONObject(i);
// for(int j = myIngredientAdapter.getCount()-1; j>=0; j--){// if (myIngredientAdapter.ingredient.get(j).checked == true) {// ingreSearch = "*"+myIngredientAdapter. checkBox.getText().toString()+"*";
// Log.i("TTT", ingreSearch);// }
// }
String name = orderbasic.getString("name"); String maker = orderbasic.getString("maker"); String ingre = orderbasic.getString("ingre"); Integer id = new Integer(orderbasic.getInt("id")); if (!hashData.containsKey(id)) {// add
Recipe recipe = new Recipe();
recipe.id = id;
recipe.name = name;
recipe.maker = maker;
recipe.ingre = ingre;
hashData.put(id, recipe);
}
}
}
catch (JSONException e) {e.printStackTrace();
}
setListView();
break;
MyIngredientAdapter
package com.example.mainmenu.searching;
import java.util.ArrayList;
import com.example.mainmenu.R;
import com.example.mainmenu.R.id;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class MyingredientAdapter extends BaseAdapter {Context mainContext;
LayoutInflater inflater;
ArrayList<MyIngredient> ingredient;
int layout;
CheckBox checkBox;
public MyingredientAdapter(Context context, int layout){this(context, layout, new ArrayList<MyIngredient>());
}
public MyingredientAdapter(Context context, int layout, ArrayList<MyIngredient> src){mainContext = context;
this.layout = layout;
inflater = (LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
ingredient = src;
}
public void removeChecked(){ for(int i=ingredient.size()-1; i>=0; i--){ if (ingredient.get(i).checked == true) {ingredient.remove(i);
}
}
}
public void add(MyIngredient myingredient) {// TODO Auto-generated method stub
ingredient.add(myingredient);
}
public int getCount() {return ingredient.size();
}
public MyIngredient getItem(int position) {return ingredient.get(position);
}
public long getItemId(int position) {// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) { if(convertView == null){convertView = inflater.inflate(layout, parent, false);
}
final MyIngredient mi = getItem(position);
TextView ingredientName = (TextView)convertView.findViewById(R.id.ingredientName);
ingredientName.setText(mi.ingreName);
checkBox = (CheckBox)convertView.findViewById(R.id.checkBox);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked==true){mi.checked = true;
}
else
mi.checked = false;
}
});
checkBox.setChecked(mi.checked); //체크된상태가 초기화되게함
return convertView;
}
}



