所以我有一个文本框,我想在点击时做一个ImageView,当你点击它时,文本框中的文字将会改变。我怎么能这样做?
我目前的代码是
Package com.momentum.snakeEncyclopedia;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
public class ballpython extends Activity implements View.OnClickListener {
//Variable for main image
ImageView display;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.ballpython);
// Image Views set
display = (ImageView) findViewById(R.id.ballpython2);
ImageView image1 = (ImageView) findViewById(R.id.region);
ImageView video = (ImageView) findViewById(R.id.video);
ImageView home = (ImageView) findViewById(R.id.home);
// Set on Click Listeners
image1.setOnClickListener(this);
video.setOnClickListener(this);
home.setOnClickListener(this);
}
// set the on clicks here
public void onClick(View v) {
switch (v.getId()) {
case R.id.region:
display.setImageResource(R.drawable.ballpython1);
findViewById(R.id.other).setVisibility(View.INVISIBLE);
findViewById(R.id.leftarrow).setVisibility(View.INVISIBLE);
findViewById(R.id.rightarrow).setVisibility(View.INVISIBLE);
break;
case R.id.video:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
break;
case R.id.home:
display.setImageResource(R.drawable.ballpython2);
findViewById(R.id.leftarrow).setVisibility(View.VISIBLE);
findViewById(R.id.rightarrow).setVisibility(View.VISIBLE);
findViewById(R.id.other).setVisibility(View.VISIBLE);
break;
}
}
}
答案 0 :(得分:0)
在您的用例场景中,您可以使用XML文件中的“onclick”属性。输入要调用的方法的名称(不带括号),然后实现该方法,将View作为唯一参数。
http://developer.android.com/resources/articles/ui-1.6.html 滚动到底部,您将看到用法示例。