假设我的一个屏幕有多个ImageButton对象,每个对象应该在单击时启动一个唯一的网站。例如,如果ImageButtons上有各种餐馆标识(汉堡王,温迪等)的图片,那么点击带有Wendys标志的ImageButton" wendys.com"会打开的。如果每个ImageButton的id类似于
android:id="@+id/wendys"
是否有任何方法可以使我在java中的launchWebsite()方法看起来像
public void launchWebsite(View view) {
Intent openURL = new Intent(android.content.Intent.ACTION_VIEW);
openURL.setData(Uri.parse("https://www." + [insert id here] + ".com"));
startActivity(openURL);
}
非常感谢,我对Android Studios来说相对较新
答案 0 :(得分:0)
您需要为每个ImageView添加 onClickListener 并稍微修改您的方法:
更改参数以传递字符串(您是否需要传递视图?如果是,请将其保留在那里)
Dim xmlDoc, Game, GameName, GameRating
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.load("C:\test.xml")
For Each Game In xmlDoc.SelectNodes("/menu/game")
REM For Each Game In xmlDoc.SelectNodes("/menu/game[@name='007 - Agent Under Fire (USA)']")
GameName = Game.getAttribute("name")
GameRating = Game.selectSingleNode("rating").text
MsgBox GameName & " ------- " & GameRating
Next
方法:
REM For Each Game In xmlDoc.SelectNodes("/menu/game")
For Each Game In xmlDoc.SelectNodes("/menu/game[@name='007 - Agent Under Fire (USA)']")
GameName = Game.getAttribute("name")
GameRating = Game.selectSingleNode("rating").text
MsgBox GameName & " ------- " & GameRating
Next