1

您好我實現了一個SearchView,它顯示了一個ListView中的結果。我面臨的問題是我有一個自定義的鍵盤和我的列表視圖重疊在keyboardView,所以我不能夠按一些我要實現我的keyboard.What的鑰匙是我的ListView中KeyboardView.Here下顯示是我的佈局文件在鍵盤視圖頂部的Android列表視圖

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/basic_bg" > 

<android.inputmethodservice.KeyboardView 
    android:id="@+id/keyboardView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:visibility="gone" /> 



<SearchView 
    android:id="@+id/searchView" 
    android:layout_width="400dp" 
    android:layout_height="40dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignRight="@+id/textView3" 
    android:layout_marginLeft="49dp" 
    android:layout_marginTop="25dp" 
    android:layout_toRightOf="@+id/imageViewUp" 
    android:background="@drawable/delete_bg_5line" 
    android:ems="10" 
    android:hint="Destination Input Text" 
    android:textColor="#87CEFA" > 
</SearchView> 

<ListView 
    android:id="@+id/main_list_View" 
    android:layout_width="450dp" 
    android:layout_height="235dp" 
    android:layout_alignLeft="@+id/searchView" 
    android:layout_below="@+id/searchView" 
    android:listSelector="@android:color/transparent" 
    android:scrollbars="none" > 
</ListView> 

</RelativeLayout> 

另外我想,當用戶瀏覽ListView控件隱藏定製鍵盤 和改變鍵盤可見度的代碼

searchtextView.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method st4ub 
      toggleKeyboardVisibility(searchtextView); 

     } 

     private void toggleKeyboardVisibility(
       AutoCompleteTextView searchViewWidget) { 
      KeyboardView keyboardView = (KeyboardView) findViewById(R.id.keyboardView); 
      int visibility = keyboardView.getVisibility(); 
      switch (visibility) { 
      case View.VISIBLE: 
       keyboardView.setVisibility(View.GONE); 
       break; 
      case View.GONE: 
      case View.INVISIBLE: 
       keyboardView.setVisibility(View.VISIBLE); 
       searchtextView = searchViewWidget; 
       break; 
      } 
     } 

    }); 

另一件事我想要做的就是更改背景爲我的鍵盤上的按鍵。我沒能做到這一點,我嘗試添加機器人:keyIcon屬性,每個鍵的,但它沒有工作,只有當我使用此屬性時,預覽背景圖像會發生變化。我該如何去做這件事。

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android" 
android:horizontalGap="0px" 
android:keyBackground="@drawable/custom_keyboard_press_onekey" 
android:keyWidth="10%p" 
android:verticalGap="0px" > 

<Row> 

    <Key 
     android:codes="1" 
     android:iconPreview="@drawable/custom_keyboard_press_onekey" 
     android:isRepeatable="true" 
     android:keyEdgeFlags="left" 
     android:keyIcon="@drawable/custom_keyboard_press_onekey" 
     android:keyLabel="1" /> 
</Row> 
</Keyboard> 

這就是我如何實例化鍵盤

final KeyboardView keyboardView = (KeyboardView) findViewById(R.id.keyboardView); 
    Keyboard keyboard = new Keyboard(this, R.layout.keyboard); 
    keyboardView.setKeyboard(keyboard); 
    keyboardView.setEnabled(true); 
    keyboardView.setPreviewEnabled(true); 

    keyboardView.setOnKeyboardActionListener(this); 

有人可以請指導我在哪裏,我錯了或建議,應該怎樣的幫助proceed.Thanks。

+0

嘿如果我創建以上述方式我得到以下錯誤「指定的孩子已經有一個父的佈局。你必須調用首先將子對象的父視圖的removeView()移除「。你知道嗎? – Anu

回答

1

要查看你的鍵盤輸入的ListView以上,你的佈局更改爲,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/basic_bg" > 

<SearchView 
    android:id="@+id/searchView" 
    android:layout_width="400dp" 
    android:layout_height="40dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignRight="@+id/textView3" 
    android:layout_marginLeft="49dp" 
    android:layout_marginTop="25dp" 
    android:layout_toRightOf="@+id/imageViewUp" 
    android:background="@drawable/delete_bg_5line" 
    android:ems="10" 
    android:hint="Destination Input Text" 
    android:textColor="#87CEFA" > 
</SearchView> 

<ListView 
    android:id="@+id/main_list_View" 
    android:layout_width="450dp" 
    android:layout_height="235dp" 
    android:layout_alignLeft="@+id/searchView" 
    android:layout_below="@+id/searchView" 
    android:listSelector="@android:color/transparent" 
    android:scrollbars="none" > 
</ListView> 


<android.inputmethodservice.KeyboardView 
    android:id="@+id/keyboardView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:visibility="gone" /> 

</RelativeLayout> 
+0

感謝這至少解決了我的一個問題。 –