gpt4 book ai didi

android - 在 fragment 实现中,EditText 下面的 ListView 在将(EditText View 的)键盘元素设置为隐藏后消失

转载 作者:太空狗 更新时间:2023-10-29 14:01:54 24 4
gpt4 key购买 nike

this is image while useing keypad

and this image after keypad was hidden

我使用 EditText 但在它下面有 ListView。在 EditText 中键入文本输入后,然后按完成或单击返回以隐藏小键盘。然后键盘后面的ListView部分消失了,取而代之的是白色区域(清除),为什么?

注意:此 fragment 位于 tablayout 和 viewpager 下,包含编辑文本和 ListView 的 fragment 是从主 fragment 启动的这是主要 fragment

    public class FriendsFragment extends Fragment {

public FriendsFragment() {
// Required empty public constructor
}
private FragmentActivity myContext;

private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onAttach(Activity activity) {
myContext=(FragmentActivity) activity;
super.onAttach(activity);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootview=inflater.inflate(R.layout.friends_fragment, container, false);


viewPager = (ViewPager) rootview.findViewById(R.id.viewpager);
setupViewPager(viewPager);

tabLayout = (TabLayout) rootview.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);

tabLayout.setupWithViewPager(viewPager);

tabLayout.setOnTabSelectedListener(
new TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
@Override
public void onTabSelected(TabLayout.Tab tab) {
super.onTabSelected(tab);

if (tab.getPosition() == 1) {
FindFriendsFragment.myfriends_list.invalidate(FindFriendsFragment.myfriends_list.getLeft(), FindFriendsFragment.myfriends_list.getTop(), FindFriendsFragment.myfriends_list.getRight(), FindFriendsFragment.myfriends_list.getBottom());
FindFriendsFragment.adapter.notifyDataSetChanged();
FindFriendsFragment.myfriends_list.clearFocus();
FindFriendsFragment.myfriends_list.postInvalidate();
}


}
});





TextView friends = (TextView) rootview.findViewById(R.id.search);
Typeface Exo_thin = Typeface.createFromAsset(myContext.getAssets(), "fonts/Exo2.0-Thin.otf");
friends.setTypeface(Exo_thin);
return rootview;

}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager());
adapter.addFragment(new MyFriendsFragment(), "My Friends");
adapter.addFragment(new FindFriendsFragment(), "Find Friends");
adapter.addFragment(new TwoFragment(), "Friend Requests");
viewPager.setAdapter(adapter);
}

class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();

public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}

@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}

@Override
public int getCount() {
return mFragmentList.size();
}

public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);

mFragmentTitleList.add(title);
}

@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}

这是主要 fragment 的xml

    <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
>


<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:id="@+id/rel"
android:layout_alignParentTop="true"

android:weightSum="1">

<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/search"
android:text="Friends"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:textSize="25sp"
android:textColor="@color/colorVeryDarkBlue"
/>

</RelativeLayout>


<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
app:tabSelectedTextColor="@color/colorLightGreen"
app:tabTextColor="@color/colorDarkGreen"
app:tabMode="scrollable"
android:background="@color/colorDarkBlue"

app:tabIndicatorColor="@color/colorDarkBlue"

app:tabGravity="center"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

包含 ListView 和编辑文本的 fragment

    public class FindFriendsFragment extends Fragment {

public FindFriendsFragment()
{
// Required empty public constructor
}
ListView myfriends_list;
FindFriendsAdapter adapter;
ArrayList<FindFriends> arraylist ;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootview= inflater.inflate(R.layout.find_friends_fragment, container, false);

EditText search=(EditText) rootview.findViewById(R.id.search);

Typeface Exo_Regular =

Typeface.createFromAsset(getActivity().getAssets(), "fonts/Exo2.0-
Regular.otf");
search.setTypeface(Exo_Regular);
arraylist = new ArrayList<FindFriends>();
arraylist.add(new FindFriends("mina fared", "hello
guys",1,"sdsdsdsds",true )) ;

adapter = new FindFriendsAdapter(getActivity(), arraylist);

myfriends_list.setAdapter(adapter);
adapter.notifyDataSetChanged();


return rootview;
}

}

相关的xml文件是包含listview和edittext的 fragment :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="#ffffff"
>



<LinearLayout
android:layout_height="60dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginTop="111dp"
android:id="@+id/refl"
android:background="@color/colorLightGrey"
android:layout_alignParentTop="true"
>

<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/search"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:background="#ffffff"
android:singleLine="true"
android:hint="Search"
android:ellipsize="start"
android:imeOptions="actionDone"
android:gravity="center_vertical|center_horizontal"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:textColorHint="@color/colormyhintfindfiernds"
android:textColor="@color/colorDarkBlue"


/>

</LinearLayout>

<ListView
android:id="@+id/listview"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:layout_marginTop="1dp"
android:layout_below="@+id/refl"
android:divider="#ffffff"
android:dividerHeight="1.5dp"
/>


</RelativeLayout>

这是包含所有 fragment 的父 fragment

    public class ProfileFragment extends Fragment {

public ProfileFragment()
{
// Required empty public constructor
}
RelativeLayout rl1;
DrawView drawView ;
DrawView drawView2;
TextView myprofile,username,notification_txt,colloection_txt,friends_txt,setting_txt,public_profile_txt;
ImageView public_profile_btn,friends;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootview=inflater.inflate(R.layout.myprofile_fragment, container,
false);


username= (TextView) rootview.findViewById(R.id.user_name_txt);
myprofile= (TextView) rootview.findViewById(R.id.myprofile);
notification_txt= (TextView) rootview.findViewById(R.id.notification_txt);
colloection_txt= (TextView) rootview.findViewById(R.id.colloection_txt);
friends_txt= (TextView) rootview.findViewById(R.id.friends_txt);
setting_txt= (TextView) rootview.findViewById(R.id.setting_txt);
public_profile_txt= (TextView) rootview.findViewById(R.id.public_profile_txt);


Typeface Exo_thin = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Exo2.0-Thin.otf");
Typeface Exo_SemiBold = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Exo2.0-SemiBold.otf");

myprofile.setTypeface(Exo_thin);
username.setTypeface(Exo_SemiBold);
notification_txt.setTypeface(Exo_SemiBold);
colloection_txt.setTypeface(Exo_SemiBold);
friends_txt.setTypeface(Exo_SemiBold);
setting_txt.setTypeface(Exo_SemiBold);
public_profile_txt.setTypeface(Exo_SemiBold);
ImageView x=(ImageView)rootview.findViewById(R.id.colloection);
ImageView y=(ImageView)rootview.findViewById(R.id.friends);
ImageView x1=(ImageView)rootview.findViewById(R.id.setting);
rl1 =(RelativeLayout)rootview.findViewById(R.id.rel2);


final View fragmentContainer = rootview.findViewById(R.id.container);

friends =(ImageView)rootview.findViewById(R.id.friends);
public_profile_btn=(ImageView)rootview.findViewById(R.id.public_profile);
public_profile_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{


Fragment newFragment = new MyProfileFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(fragmentContainer.getId(), newFragment);

transaction.addToBackStack(null);
transaction.commit();

}
});

friends.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{


Fragment newFragment = new FriendsFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(fragmentContainer.getId(), newFragment);

transaction.addToBackStack(null);
transaction.commit();

}
});

return rootview;
}

最佳答案

从 manifest.xml 中搜索这样的 Activity 标签

<activity
android:name=".YourActivity"
android:label="@string/title_activity"
...>
</activity>

然后像那样添加 android:configChanges="keyboard|keyboardHidden"

<activity
android:name=".YourActivity"
android:configChanges="keyboard|keyboardHidden"
android:label="@string/title_activity"
...>
</activity>

编辑

我发现我的回答不完全正确你可以补充

android:windowSoftInputMode="adjustNothing"

对不起

关于android - 在 fragment 实现中,EditText 下面的 ListView 在将(EditText View 的)键盘元素设置为隐藏后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35032929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com