调用setLayoutParams();时,Listview中的EditText光标移到最前面。

时间:2018-08-31 02:15:30

标签: java android android-edittext cursor

我在EditText内的RelativeLayout(在下面的代码中命名为TopLayout)内有一个ListViewEditText上有TextWatcher,它可以更改RelativeLayout(和ListView)的高度。但是,当高度发生变化时,EditText内的光标会移到开头。

反正有没有办法让它保持原样?

public void setItemHeight(int itemPos, int itemHeight) {
    if (mChallengingThoughtsListView != null) {

        View itemView = mChallengingThoughtsListView.getChildAt(itemPos);
        LinearLayout topLayout = itemView.findViewById(R.id.TopLayout);

        // Set item height
        ViewGroup.LayoutParams params = topLayout.getLayoutParams();
        params.height = itemHeight;
        topLayout.setLayoutParams(params);

        // TODO: Put code to place cursor back where it was
    }
}

0 个答案:

没有答案