gpt4 book ai didi

java - 在Recyclerview项目Mainactivity中创建url对象,Adapter在默认浏览器中解析加载Url。尝试在 WebView 中?

转载 作者:行者123 更新时间:2023-12-02 04:32:56 25 4
gpt4 key购买 nike

MainActivity 代码中有图像、名称和 URL 对象,可在回收器项目中查看:

  protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(getResources().getString(R.string.app_name));
recyclerView = findViewById(R.id.recyclerView);

images = new int[]{R.drawable.google, R.drawable.facebook,
R.drawable.gaana, R.drawable.youtube, R.drawable.oracle,
R.drawable.wikipedia};

webNames = new String[]{"Google", "Gacebook", "Gaana",
"YouTube", "Oracle", "Wikipedia"};

webUrl = new String[]{"https://www.google.com.",
"https://www.facebook.com",
"https://www.gaana.com",
"https://www.youtube.com",
"https://www.oracle.com",
"https://www.wikipedia.org"};

包含图像、名称和 Url 的适配器,解析为 recyclerview 项目并通过 onClicklistener 在默认浏览器中加载:

 @Override
public void onBindViewHolder(final PlaceViewHolder holder, int position) {
holder.webName.setText(webNames[position]);
holder.wIcon.setImageResource(images[position]);

holder.wIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Intent intent = new Intent(context, WebPage.class);
intent.putExtra("webUrl", webUrl.toString());
// Intent intent = new Intent(Intent.ACTION_VIEW);
// intent.setData(Uri.parse(placeGuide[holder.getAdapterPosition()]));
context.startActivity(intent);
}
});
}

尝试在 webview 中加载 url:


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_page);
WebView webView = findViewById(R.id.weView);

webView.getSettings().setJavaScriptEnabled(true);
Bundle bundle = getIntent().getExtras();
webView.loadUrl(bundle.getString("webUrl"));
}

我想在Webview中加载Url

最佳答案

回收 View

Intent intent = new Intent(context, WebPage.class);
intent.putExtra("webUrl", webUrl[position]);
context.startActivity(intent);

另一项 Activity

Intent intent=getIntent();
String url=intent.getStringExtra("webUrl");
webView.loadUrl(url);

关于java - 在Recyclerview项目Mainactivity中创建url对象,Adapter在默认浏览器中解析加载Url。尝试在 WebView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56568110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com