У меня проблема с моим приложением Я делаю, я хочу составить список на ANDROID с фотографиями, взятыми из GSON. но мне интересно, как взять текст и url для изображения, сделанного списком.ListView с изображением от Json
GSON
[{"brand_city_id":"1","name":"Blue Bird","logo":"http:\/\/gojek.gits.co.id\/uploads\/Blue_Bird1.jpg","description":"Blue bird adalah salah satu member blue bird group, menyediakan jasa taksi dengan harga terjangkau."},{"brand_city_id":"5","name":"Cipaganti","logo":"http:\/\/gojek.gits.co.id\/uploads\/Cipaganti.png","description":"Bertemakan taksimax, Cipaganti Taksi bukan hanya sekedar pengantaran pelanggan di dalam kota, fasilitas lengkap adalah salah satu keunggulan taksimax ini. Dengan fasilitas Wi-Fi dan Movie serta kelengkapan kendaraan yang memadai telah membedakan layanan taksimax dengan taksi yang lainnya."}]
и Main.java
package com.gits.pikmiap;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.taxibandung);
ArrayList<SearchResults> searchResults = GetSearchResults();
final ListView lv1 = (ListView) findViewById(R.id.ListView01);
lv1.setAdapter(new MyCustomBaseAdapter(this, searchResults));
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv1.getItemAtPosition(position);
SearchResults fullObject = (SearchResults)o;
Toast.makeText(Main.this, "You have chosen: " + " " + fullObject.getName(), Toast.LENGTH_LONG).show();
}
});
}
private ArrayList<SearchResults> GetSearchResults(){
ArrayList<SearchResults> results = new ArrayList<SearchResults>();
SearchResults sr1 = new SearchResults();
sr1.setName("Blue Bird");
sr1.setDescription("Blue bird adalah salah satu member blue bird group, menyediakan jasa taksi dengan harga terjangkau.");
sr1.setPhone("214-555-1234");
sr1.setImage("http://gojek.gits.co.id/uploads/Blue_Bird1.jpg");
results.add(sr1);
sr1 = new SearchResults();
sr1.setName("Cipaganti");
sr1.setDescription("Bertemakan taksimax, Cipaganti Taksi bukan hanya sekedar pengantaran pelanggan di dalam kota, fasilitas lengkap adalah salah satu keunggulan taksimax ini. Dengan fasilitas Wi-Fi dan Movie serta kelengkapan kendaraan yang memadai telah membedakan layanan taksimax dengan taksi yang lainnya.");
sr1.setPhone("612-555-0961");
sr1.setImage("http://gojek.gits.co.id/uploads/cipaganti.ppg");
results.add(sr1);
return results;
}
}
SearchResults.java
package com.gits.pikmiap;
public class SearchResults {
private String name = "";
private String description = "";
private String phone = "";
private String image = "";
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPhone() {
return phone;
}
public void setImage(String image) {
this.image = image;
}
public String getImage() {
return image;
}
}
MyCustomBaseAdapter.java
package com.gits.pikmiap;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MyCustomBaseAdapter extends BaseAdapter {
private static ArrayList<SearchResults> searchArrayList;
private LayoutInflater mInflater;
public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results) {
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_view, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.name);
holder.txtCityState = (TextView) convertView.findViewById(R.id.cityState);
holder.txtPhone = (TextView) convertView.findViewById(R.id.phone);
holder.image = (ImageView) convertView.findViewById(R.id.image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtName.setText(searchArrayList.get(position).getName());
holder.txtCityState.setText(searchArrayList.get(position).getDescription());
holder.txtPhone.setText(searchArrayList.get(position).getPhone());
holder.image.setImageURI(null);
return convertView;
}
static class ViewHolder {
ImageView image;
TextView txtName;
TextView txtCityState;
TextView txtPhone;
}
}
, где я должен поставить источник? извините, я новичок :( –
@DeniRohimat этот источник должен быть предоставлен после раздела, где вы получите ответ json с сервера. – Basil
oke @Basil thx для вашего ответа: D –