私はピカソの[ロード(URL)]にURLの値を入れたいと思っています。しかし、私はTextviewにURLの値を読み込むことができます。私は非常に簡単なことを知って助けてください。私は助けが必要です(初心者)Picasso Dynamic ImageのURLを渡す
package com.maasin.map.anew.model;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.maasin.map.anew.R;
import com.maasin.map.anew.model.model.Local;
import com.squareup.picasso.Picasso;
import java.util.LinkedList;
import java.util.List;
import static android.R.attr.defaultValue;
import static android.R.attr.drawable;
import static android.R.attr.name;
import static android.R.attr.value;
import static android.R.attr.valueFrom;
/**
* Created by Carl Christian on 11/02/2017.
*/
public class establishment extends AppCompatActivity implements OnMapReadyCallback {
TextView Name;
// TextView Name2;
TextView add;
TextView Categ;
TextView oStart;
TextView oEnd;
Toolbar tool;
String s;
private FirebaseDatabase database;
double latt = 124.838767;
double longg = 10.134265;
double longitude = 124.831786 ;
double latitude = 10.130952;
//String url;
// List<String> urls = new LinkedList<String>();
Context ctx = this;
private GoogleMap mMap;
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
database = FirebaseDatabase.getInstance();
final DatabaseReference establishments = database.getReference("establishments");
FirebaseStorage storage = FirebaseStorage.getInstance();
s = getIntent().getStringExtra("PRIMEKEY");
String s2 = getIntent().getStringExtra("PRIMEKEY2");
latitude= getIntent().getDoubleExtra("location", defaultValue);
longitude= getIntent().getDoubleExtra("location1", defaultValue);
// Toast.makeText(this,Double.toString(l), Toast.LENGTH_SHORT).show();
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// Toast.makeText(establishment.this, s2, Toast.LENGTH_SHORT).show();
//SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
// .findFragmentById(R.id.map);
//mamapFragment.getMapAsync(this);
//map.addMarker(new MarkerOptions()
// .position(new LatLng(124.838767, 10.134265))
// .title("Hello world"));
// StorageReference storageRef = storage.getReferenceFromUrl("gs://newtest-e7dff.appspot.com/");
//StorageReference imagesRef = storageRef.child(s2);
//from main activity , title action bar
Name = (TextView) findViewById(R.id.Name);
//Name.setText(s2);
// Name2 = (TextView) findViewById(R.id.Name2);
add = (TextView) findViewById(R.id.add);
// Name2.setText(s2);
oStart = (TextView) findViewById(R.id.oStart);
oEnd = (TextView) findViewById(R.id.oEnd);
Categ = (TextView) findViewById(R.id.Categ);
getSupportActionBar().setTitle(s);
//FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
// DatabaseReference mref = firebaseDatabase.getReference();
establishments.child(s2).child("Estab_url").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// String url = dataSnapshot.child("url").getValue(String.class);
// url = dataSnapshot.child("url").getValue(String.class);
// Name.setText(Html.fromHtml("“" + url + "”"));
// String gg = (Html.fromHtml("“" + url + "”"));
//urls.add(url);
// Name.setText(url);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Picasso.with(ctx)
.load(dataSnapshot.child("url").getValue(String.class))
.resize(200,100)
.into(imageView);
}
public void onChildChanged(DataSnapshot dataSnapshot, String s) { }
public void onChildRemoved(DataSnapshot dataSnapshot) { }
public void onChildMoved(DataSnapshot dataSnapshot, String s) { }
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException(); // don't ignore onCancelled
}
});
// Name.setText(urls);
// ImageView imageView = (ImageView) findViewById(R.id.imageView);
// Name.setText(url);
// Picasso.with(this)
// .load(url)
// .resize(200,100)
// .into(imageView);
// String x = establishments.child(s2).child("Estab_name").toString();
// Name2.setText(x);
// final DatabaseReference establishments = database.getReference("establishments");
establishments.child(s2).child("Estab_name").addListenerForSingleValueEvent(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = (String) dataSnapshot.getValue();
//Name.setText(value);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
// establishments.child(s2).child("latitude").addValueEventListener(new ValueEventListener() {
// @Override
// public void onDataChange(DataSnapshot dataSnapshot) {
// String value = (String) dataSnapshot.getValue();
// double amount = Double.parseDouble(value);
//latitude= amount;
// Toast.makeText(this,value, Toast.LENGTH_SHORT).show();
// }
// @Override
// public void onCancelled(DatabaseError databaseError) {
// }
// });
// establishments.child(s2).child("longitude").addValueEventListener(new ValueEventListener() {
// @Override
// public void onDataChange(DataSnapshot dataSnapshot) {
// String value = (String) dataSnapshot.getValue();
// double amount = Double.parseDouble(value);
// longitude= amount;
//}
// @Override
// public void onCancelled(DatabaseError databaseError) {
// }
// });
establishments.child(s2).child("Estab_add").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = (String) dataSnapshot.getValue();
add.setText(value);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
establishments.child(s2).child("Estab_category").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = (String) dataSnapshot.getValue();
Categ.setText(value);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
establishments.child(s2).child("Estab_Officestart").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = (String) dataSnapshot.getValue();
oStart.setText(value);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
establishments.child(s2).child("Estab_Officeout").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = (String) dataSnapshot.getValue();
oEnd.setText(value);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(latitude, longitude);
float zoomLevel = 16;
mMap.addMarker(new MarkerOptions().position(sydney).title(s));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, zoomLevel));
}
}
毎日質問...コード内の 'onChildXXX()'は非同期に実行されます。それは、あなたがURLを取得する前にそのコードが実行されることを意味します –