火力地堡數據庫的WebView實現我想要實現webView的與火力地堡所以,如果我在火力數據庫添加URL它就會在我的web視圖應用在實時實施,我已經通過數據庫成功地實現了文本和圖像,但無法正常使用webView,我搜索了很多選項,但都不適合我,請幫忙。如果你想要更多的細節,我可以提供給你。與Android的
我使用過Android Studio
下面是我的火力地堡實施的圖像和文本的Java類代碼
@Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null) {
sentToStart();
}
FirebaseRecyclerAdapter <post, postViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<post, postViewHolder>(
post.class,
R.layout.post_row_recycle_home,
postViewHolder.class,
mDatabaseReference
) {
@Override
protected void populateViewHolder(postViewHolder viewHolder, post model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setdescription(model.getDescription());
viewHolder.setimage(getApplicationContext(), model.getImage());
viewHolder.setsource(model.getSource());
}
};
mrecyclerView.setAdapter(firebaseRecyclerAdapter);
}
public static class postViewHolder extends RecyclerViewPager.ViewHolder{
View mView;
public postViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title){
TextView post_title = (TextView)mView.findViewById(R.id.title_cardView);
post_title.setText(title);
}
public void setsource(String source){
TextView post_source = (TextView)mView.findViewById(R.id.source_cardView);
post_source.setText(source);
}
public void setdescription(String description){
TextView post_description = (TextView)mView.findViewById(R.id.description_cardView);
post_description.setText(description);
}
public void setimage(final Context ctx, final String image){
final ImageView post_image = (ImageView)mView.findViewById(R.id.post_image);
Picasso.with(ctx).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(post_image, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Picasso.with(ctx).load(image).into(post_image);
}
});
}
}
的getter/setter的Java類
public class post {
private String title;
private String description;
private String image;
private String source;
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public post(){
}
public post(String title, String description, String image, String source) {
this.title = title;
this.description = description;
this.image = image;
this.source = source;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
已更新的WebView的Java活動
public class webViewNews extends AppCompatActivity {
private WebView webviewthis;
private DatabaseReference mDatabaseReference;
private DatabaseReference mdataRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview_page);
mdataRef = FirebaseDatabase.getInstance().getReference().child("webView");
webviewthis = (WebView)findViewById(R.id.webView_news);
webviewthis.setWebViewClient(new WebViewClient());
webviewthis.getSettings().setJavaScriptEnabled(true);
webviewthis.getSettings().setLoadsImagesAutomatically(true);
mdataRef.child("webView").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.child("webView").getValue();
webviewthis.loadUrl("");
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
protected void onStart() {
super.onStart();
}
}
您尚未顯示您在WebView中嘗試過的內容。 –
你可以分享我們的WebView嗎? –
@AlexMamo肯定我會在我的問題編輯 –