我创建的用于打开图像的一段代码需要我在单词上单击两次才能打开图像。我不明白为什么它不响应一键。
这里的布局是 TextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="The New Yorker"
android:id="@+id/the_new_yorker"
android:textStyle="italic"
android:textColor="@color/blue"
android:onClick="new_yorker_cartoon"/>
这是java文件中的相应函数
public void new_yorker_cartoon(View view) {
final TextView TextGenerique = (TextView) findViewById(R.id.the_new_yorker);
View.OnClickListener monEcouteur = new View.OnClickListener() {
@Override
public void onClick(View v) {
String imageUrl = "http://www.lapasserelle.com/english/l09/imgs/new_yorker.gif";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(imageUrl), "image/gif");
startActivity(intent);
}
};
TextGenerique.setOnClickListener(monEcouteur);
}
我不明白的是为什么我需要在 New Yorker 上单击两次才能在手机上显示图像 new_yorker.gif。