[英]How to remove white space in AutoCompleteTextView
How can I remove the white space that automatically typed together with the letter(s) in my autocompletetextview whenever I click my imagebutton(s)? 每当我单击图像按钮时,如何删除自动完成文本视图中与字母一起自动键入的空白? and how can I make my imagebuttons' picture back to the first image (because here when the imagebutton is clicked the color of the image change and I want it to set back its original image after clicking a button) for example here using mycodes: from a to changea and back to a.
以及如何将我的imagebuttons的图片恢复为第一张图片(因为在这里单击imagebutton时,图片更改的颜色,并且我希望它在单击按钮后重新设置其原始图片),例如在这里使用mycodes:from a更改为a,然后返回a。 Heres my code:
这是我的代码:
public void onClick(View arg0) { Log.i(TAG,"arg0.getId()="+arg0.getId()); if (arg0.getId()==R.drawable.a){ Log.i(TAG,"arg0.getId()="+arg0.getId()); generatedString=generatedString+("a"); text.setText(generatedString); ((ImageButton) arg0).setImageResource(R.drawable.changea);
a) To remove whitespace in a String use the method trim() a)要删除字符串中的空格,请使用trim()方法
b) to change the image located into your resources of an ImageView use the method setImageResource() this is an example: b)使用方法setImageResource( )来更改位于ImageView资源中的图像,这是一个示例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:id="@+id/button1"
android:layout_width="120dp"
android:layout_height="120dp"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cat" />
</LinearLayout>
Heres the code to change from an image "cat" to "dog". 这是从图像“猫”更改为“狗”的代码。
Button btn;
ImageView img;
boolean click ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
img = (ImageView)findViewById(R.id.imageView1);
if(click){
img.setImageResource(R.drawable.cat);
click = false;
}else{
img.setImageResource(R.drawable.dog);
click = true;
}
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.