에 따라 LazyAdapter와 응용 프로그램 사용의 ListView를 구축하지만 내 목록보기에 anomali이 있습니다. 각 목록보기에는 1 개의 이미지보기와 2 개의 텍스트보기가 있습니다. 너무 게으른 어댑터 ... 는 데이터베이스에서 이미지 미리보기를 표시 할 수 있습니다 ... 이미지 뷰가 coorect입니다 ... 이미지 뷰와 "이름"Textview1 및 Textview2에 "주소"를 "썸네일"
를 표시합니다 그러나 여기의 문제는 두 텍스트 모두 올바른 데이터를 표시하지 못했습니다! 대신 데이터베이스에서 "이름"과 "주소"를 표시합니다 ... THUMBNAIL IMAGE에 대한 링크를 표시합니다.
누군가가 나를 도와 줄 수 있습니다. thanks b4. 감사합니다. 여기
내 JSON의 :{
"listresto": [
{
"nama_resto": "CIE RASA LOOM",
"alamat_resto": "JL. BUAH BATU No.154 Bandung",
"thumb_img": "http://10.0.2.2/culigui/images/resto_thumb/cierasaloom.JPG"
},
{
"nama_resto": "AYAM GORENG SUHARTI",
"alamat_resto": "Jl. Lodaya No. 1",
"thumb_img": "http://10.0.2.2/culigui/images/resto_thumb/ayamgorengsuharti.JPG"
},
{
"nama_resto": "BAKSO ENGGAL MALANG",
"alamat_resto": "JL. BURANGRANG 12 BANDUNG",
"thumb_img": "http://10.0.2.2/culigui/images/resto_thumb/baksoenggal.JPG"
},
{
"nama_resto": "ATMOSPHERE",
"alamat_resto": "Jl.Lengkong Besar No.97",
"thumb_img": "http://10.0.2.2/culigui/images/resto_thumb/atmosphere.JPG"
},
{
"nama_resto": "WARUNG STEAK AND SHAKE",
"alamat_resto": "Jl. Jend Gatot Subroto 28",
"thumb_img": "http://10.0.2.2/culigui/images/resto_thumb/warungsteak.JPG"
}
]
}
여기 내 주요 활동입니다 :
public class MenuViewAll extends Activity {
// url to make request
private static String url = "http://10.0.2.2/culigui/getdataresto.php";
public static String KEY_ID,KEY_NAME,KEY_ADDRESS,KEY_THUMB;
ListView Listview;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_view_all);
// Hashmap for ListView
ArrayList<HashMap<String, String>> userList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
try {
// Getting JSONArray of listresto
JSONArray listresto = json.getJSONArray("listresto");
// looping through All listresto
for(int i = 0; i < listresto.length(); i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject list = listresto.getJSONObject(i);
// insert String to Local Variable
//map.put(KEY_ID, list.getString("id_resto"));
map.put(KEY_NAME, list.getString("nama_resto"));
map.put(KEY_ADDRESS, list.getString("alamat_resto"));
map.put(KEY_THUMB, list.getString("thumb_img"));
userList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
//this is new custom adapter
Listview = (ListView) findViewById (R.id.list);
adapter = new LazyAdapter(this, userList);
Listview.setAdapter(adapter);
여기 내 LaxyAdapter 클래스의 :이 문제를 해결
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.listitemviewall, null);
TextView namaresto = (TextView)vi.findViewById(R.id.name); // resto name
TextView alamatresto = (TextView)vi.findViewById(R.id.address); // resto address
ImageView thumb_image=(ImageView)vi.findViewById(R.id.defaultthumb); // thumb image
HashMap<String, String> resto = new HashMap<String, String>();
resto = data.get(position);
// Setting all values in listview
namaresto.setText(resto.get(MenuViewAll.KEY_NAME));
alamatresto.setText(resto.get(MenuViewAll.KEY_ADDRESS));
imageLoader.DisplayImage(resto.get(MenuViewAll.KEY_THUMB), thumb_image);
return vi;
}
}
어플이 추락했습니다 ...! – Prasad