2

とがLinearLayoutありEditTextますListViewEditTextをフィルタリングするために使用していますListView。最初に画面を表示すると、フィルタリングは正常に機能しており、ソフトキーボードが自動的にポップアップします。入力すると、入力した文字はに表示されませんEditText。をタップするとEditText、入力した文字は表示されますが、フィルターには移動しません。まるで2つEditTextあるかのようです。

これが私のxmlです:

<?xml version="1.0" encoding="utf-8"?>

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical"
     android:paddingBottom="6dip"
     android:paddingTop="4dip" >

     <EditText
         android:id="@+id/search_box"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"            
         android:inputType="text"
         android:maxLines="1"
         android:textSize="17dip" />

     <ListView
         android:id="@+id/beerListViewID"
         android:layout_width="fill_parent"
         android:layout_height="0dip"
         android:layout_weight="1" >

     </ListView>

</LinearLayout>

TextWatcherの設定は次のとおりです。

@Override public void onLoadFinished(Loader<ArrayList<BeerRecord>> loader,
        ArrayList<BeerRecord> beers) {
    // Set the new data in the adapter.
    ListView listView = (ListView) getActivity().findViewById(R.id.beerListViewID);

    myAdapter = new BeerItemAdapter(getActivity(), R.layout.beerline, beers);

    filterText = (EditText) getActivity().findViewById(R.id.search_box);
    filterText.addTextChangedListener(filterTextWatcher);

    listView.setAdapter(myAdapter);

}

そしてTextWatcher:

    private TextWatcher filterTextWatcher = new TextWatcher() {

    public void afterTextChanged(Editable s) {
    }

    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
    }

    public void onTextChanged(CharSequence s, int start, int before,
            int count) {            
        myAdapter.getFilter().filter(s);
    }

};

さらにコードを投稿する必要がありますか?なぜ2つあるように見えるのか誰にも分かりますEditTextか?

編集:アクティビティが開始され、ソフトキーボードがポップアップすると、表示可能なEditTextにフォーカスがないことがわかります。私はどういうわけか最初のものの後ろに隠されている2番目のものを定義しているに違いありません。

編集-回答:私はそれを理解しました。このフラグメントのOnCreateメソッドでは、次のようになりました。

    getActivity().setContentView(R.layout.beer_listview);

これは2番目のビューを作成していたと思います。コメントアウトすると、2番目のEditTextが消えました。

4

1 に答える 1

0

上記のコメントから繰り返しますが、8 時間が経過しました。私は何が起こったのかを理解しました:

 getActivity().setContentView(R.layout.beer_listview);

フラグメントの OnCreate にあり、「実際の」ビューの上に別のビューを配置していました。理由はよくわかりませんが、コメントアウトすると修正されました。私はそれがそのようなものだと思って、ビューに対して行ったすべての参照を検索し、コメントアウトしました。

誰かが説明したい場合は、お気軽に!

于 2012-10-07T17:04:41.733 に答える