我有一个列表视图即可从urpre中提取共享偏好数据,在每个列表视图行中都有一个我要发送到另一个活动的webview中的网址。 这是我的网页浏览活动
WebView webView;
String DEFAULT_URL = "https://www.google.co.in/";
ProgressDialog progressBar;
String YourWebName = "Put Here";
ArrayList<String> list;
String bundle=null;
SharedPreferences prefs;
SharedPreferences.Editor edit;
Set<String> set = new LinkedHashSet<String>();
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView= (WebView)findViewById(R.id.webView);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
Intent i = getIntent();
String url = i.getStringExtra("link");
prefs=this.getSharedPreferences("preferences",Context.MODE_PRIVATE);
edit=prefs.edit();
list = new ArrayList<String>();
webView.setWebViewClient(new MyWebViewClient());
if (getIntent().getExtras()!=null &&getIntent().getExtras().getString("com.parse.Data")!=null){
bundle=getIntent().getExtras().getString("com.parse.Data");
parseJson(bundle);
Log.e("notificationData", ""+bundle);
}else{
showProgressBar();
webView.loadUrl(DEFAULT_URL);
}
}
private class MyWebViewClient extends WebViewClient{
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if (progressBar!=null && progressBar.isShowing()) {
progressBar.dismiss();
}
}
}
,这是我的列表视图活动
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_notifications);
no_notifications=(TextView)findViewById(R.id.no_notifications);
prefs=this.getSharedPreferences("preferences",Context.MODE_PRIVATE);
//edit=prefs.edit();
listview=(ListView)findViewById(R.id.listView);
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Object o = listview.getItemAtPosition(position);
String str=(String)o;
Toast.makeText(ListOfNotifications.this, "You have chosen: " + " " + str.getLabel(), Toast.LENGTH_LONG).show();
Intent i = new Intent(ListOfNotifications.this,ParseStarterProjectActivity.class);
i.putExtra("link", o.getText());
startActivity(i);
}
});
if (getIntent().getExtras()!=null &&getIntent().getExtras().getStringArrayList("listData")!=null){
listData=getIntent().getExtras().getStringArrayList("listData");
if (listData!=null && listData.size()>0){
listview.setVisibility(View.VISIBLE);
no_notifications.setVisibility(View.GONE);
adapter= new ListAdapter(ListOfNotifications.this, R.layout.listview_row,listData);
listview.setAdapter(adapter);
}else{
listview.setVisibility(View.GONE);
no_notifications.setVisibility(View.VISIBLE);
}
}
答案 0 :(得分:0)
将url传递给list活动中的intent到webview活动。
从webview活动中获取该url的url,并将该url传递到webview的String str = "Here \" is one final \" example";
Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
Matcher regexMatcher = regex.matcher(str);
while (regexMatcher.find()) {
System.out.println(regexMatcher.group());
}
。
这样可行。