如何使用 Fragment 关联 webView 和 listView 项目

how can I relate webView and listView items using Fragment

在我的应用程序中,有一个片段 class 和带有简单 xml 文件的 webView class。我想单击一个 ListView 项目(邮件、堆栈等),然后加载它们的 URL。我做不到。请帮忙。 这是片段 class:

public class frags extends Fragment {
   final String[] items={"google", "facebook", "twitter", "mail", "stack"};

//有一些代码。

    myListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id)  {

           intent = new Intent ( context, web.class);
           startActivity(intent);
        }
    });
    return vw;    }

}

在你的列表视图点击监听器中像这样传递你点击的项目

 myListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id)  {

           intent = new Intent ( context, web.class);
           intent.putExtra("item_name",items.get(position));
           startActivity(intent);
        }
    });

并在您的web.class中收到物品名称

Bundle b = getIntent.getExtras;
if(b.getString("item_name").equals("facebook")){
//open facebook url
}else if (b.getString("item_name").equals("twitter")){
//open twitter url
}