Android 点击更改文本框文本
所以我有一个文本框,我想在单击时执行 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;
}
}
}
So i have a text box and i want to do a ImageView on click and when you click it the text in the textbox will change. how can i do this?
My current code is
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;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的用例场景中,您可以使用 XML 文件中的“onclick”属性。输入要调用的方法的名称(不带括号),然后以 View 作为唯一参数来实现该方法。
http://developer.android.com/resources/articles/ui-1.6.html
滚动到底部,您将看到使用示例。
In your use case scenario, you can use the "onclick" attribute in the XML file. Put in the name of the method you want to call (without parentheses) and then implement that method taking in a View as the only parameter.
http://developer.android.com/resources/articles/ui-1.6.html
Scroll to the bottom and you will see the usage example.