将 json 数据中的图像提取到列表中的列表视图中选择所有数据移动到第二个活动名称 SingleContactActivity
ListView list;
ArrayList<FeeStacture> newsFeedList;
DeliveryListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeAdress();
list = (ListView) findViewById(R.id.list);
adapter = new DeliveryListAdapter();
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// getting values from selected ListItem
String name = ((TextView) view.findViewById(R.id.rank))
.getText().toString();
String cost = ((TextView) view.findViewById(R.id.country))
.getText().toString();
String description = ((TextView) view.findViewById(R.id.population)).getText().toString();
ImageView employee_id = ((ImageView) view.findViewById(R.id.imagestar));
employee_id.buildDrawingCache();
Bitmap bitmap=employee_id.getDrawingCache();
Intent in = new Intent(getApplicationContext(),
SingleContactActivity.class);
in.putExtra("name", name);
in.putExtra("email", cost);
in.putExtra("phone", description);
in.putExtra("BitmapImage", bitmap);
startActivity(in);
}
});
}
private void initializeAdress() {
getNewsFeedListFromServer();
newsFeedList = new ArrayList<FeeStacture>();
}
private void getNewsFeedListFromServer() {
Fee_Stacture_WebService servics = new Fee_Stacture_WebService(this);
servics.startTask();
}
public class DeliveryListAdapter extends BaseAdapter
{
LayoutInflater minflat;
public DeliveryListAdapter() {
minflat = LayoutInflater.from(getApplicationContext());
}
@Override
public int getCount() {
return newsFeedList.size();
//return MainActivity.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int position, View contentView, ViewGroup arg2) {
ViewHolder holder;
if (contentView == null) {
holder = new ViewHolder();
contentView = minflat.inflate(R.layout.home_custom_listitem, null);
holder.rank = (TextView) contentView.findViewById(R.id.rank);
holder.pop = (TextView) contentView.findViewById(R.id.population);
holder.country = (TextView) contentView.findViewById(R.id.country);
holder.image = (ImageView) contentView.findViewById(R.id.imagestar);
contentView.setTag(holder);
} else
{
holder = (ViewHolder) contentView.getTag();
}
FeeStacture newsObj = newsFeedList.get(position);
holder.rank.setText(newsObj.getRank());
holder.pop.setText(newsObj.getPop());
holder.country.setText(newsObj.getCountry());
new DownloadImageTask(holder.image).execute(newsFeedList.get(position).getItemIconStr());
return contentView;
}
public class ViewHolder {
// ImageView use;
TextView rank;
TextView pop;
ImageView image;
TextView address;
TextView country;
TextView gender;
TextView phone;
}
}
@Override
public void onSuccessfullResponse(Object object) {
newsFeedList = (ArrayList<FeeStacture>) object;
adapter.notifyDataSetChanged();
}
@Override
public void onErrorResponse(String error) {
Toast.makeText(getApplicationContext(), error, Toast.LENGTH_SHORT).show();
}
@Override
public void onNetworkError(String error) {
Toast.makeText(getApplicationContext(), error, Toast.LENGTH_SHORT).show();
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
//super.onBackPressed();
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_menu_zoom)
.setTitle("Web Service Demo")
.setMessage("Are you sure you want to quit Web Demo ?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("No", null)
.show();
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}