我試圖解決它幾個小時,但一直無法。發生的事情是我設置了這個editText,稱爲活動的佈局,並將它連接到活動的變量上,當你點擊它打開視覺鍵盤的字段時,但是當你按下一個鍵時,它會把你到類似瀏覽器的搜索屏幕,而不僅僅是更新edittext的文本。編輯文本沒有收到文字
在我的XML的EDITTEXT是:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background = "@drawable/splash"
android:orientation = "vertical">
<EditText
android:id="@+id/searchEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@color/black"
android:textColorHint="@color/hintGray"
android:textSize="20dp"
android:paddingLeft="50dp"
android:paddingRight="10dp"
android:layout_marginTop="300dp"
android:background="@drawable/a01_text_box"
android:hint="Hint"
android:layout_gravity="center_horizontal" />
<ImageButton
android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/a01_boton_buscar"
android:layout_gravity="center_horizontal" />
</LinearLayout>
上的活動我做這個
public class SubscribeActivity {
private EditText searchEdit;
private ImageButton searchButton;
private Context context;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subscribe_main);
this.context = this;
findAndInitViews();
}
protected void findAndInitViews() {
searchEdit = (EditText) findViewById(R.id.searchEdit);
searchButton = (ImageButton) findViewById(R.id.searchButton);
searchButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String codeText = searchEdit.getText().toString();
Toast.makeText(context, codeText, Toast.LENGTH_LONG).show();
}
});
}
}
我仍然無法找到它不發生的方式。你可以幫我嗎?
你可以在這裏發佈你的代碼嗎? – Android 2012-07-27 13:36:47
在你試圖找到'findViewById(id)' – 2012-07-27 13:40:47
之前,你有沒有叫過'setContentView(R.layout.yourLayoutFromEditText)'是,在那裏更新了所有的代碼 – 2012-07-27 13:41:48