我的活动中有一个表格内容,其中有3个选项卡,每个选项卡内容都有一个片段,并将它们命名为OneFragment,TwoFragment和ThirdFragment
现在在我的TwoFragment类中,该类可以处理第二个选项卡内容,它具有一个ListvIEw控件.
现在的问题:
我不知道为什么列表控件不滚动!
这是我的活动代码:称之为foot_recipe类
package com.example.androID.dezcook;import androID.content.ContentValues;import androID.content.Context;import androID.content.Intent;import androID.database.Cursor;import androID.database.sqlException;import androID.database.sqlite.sqliteDatabase;import androID.os.Bundle;import androID.support.design.Widget.floatingActionbutton;import androID.support.design.Widget.Snackbar;import androID.support.design.Widget.TabLayout;import androID.support.v4.app.Fragment;import androID.support.v4.app.FragmentManager;import androID.support.v4.app.FragmentPagerAdapter;import androID.support.v4.vIEw.VIEwPager;import androID.support.v7.app.AppCompatActivity;import androID.support.v7.Widget.Toolbar;import androID.util.Log;import androID.vIEw.VIEw;import androID.Widget.TextVIEw;import androID.Widget.Toast;import java.io.IOException;import java.util.ArrayList;import java.util.List;public class Foot_recipe extends AppCompatActivity { /*Layout PropertIEs define*/ private Toolbar toolbar; private TabLayout tabLayout; private VIEwPager vIEwPager; private Food send_info; private int[] tabIcons = { R.drawable.tab_details_imagealbum, R.drawable.tab_details_cookie, R.drawable.tab_details_camera }; /*End layout propetIEs DeFinition*/ /*Start Logic deFinition from here*/ /*End Logic DeFinition*/ @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_foot_recipe); //get data from intent sended from cardvIEw String txtID = ""; Intent intent = getIntent(); // Bundle bundle=intent.getExtras(); // if(bundle!=null)txtID=bundle.getString("txtID"); Food food = (Food) intent.getParcelableExtra("food_obj"); send_info = food; //tool bar customization TextVIEw toolbar_Title = (TextVIEw) findVIEwByID(R.ID.toolbar_Title); toolbar_Title.setText(food.getTxtname()); toolbarCustomization(); //Tab customization tabCustomization(); //Customize floatting button Actionbutton_fav(food.getTxtID()); } public voID Actionbutton_fav(final int ID) { floatingActionbutton fav = (floatingActionbutton) findVIEwByID(R.ID.fav_btn_heart); fav.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (addDBfav(ID) > 0) Snackbar.make(v, "added to fav List", Snackbar.LENGTH_SHORT).show(); else Snackbar.make(v, "not in fav List", Snackbar.LENGTH_SHORT).show(); } }); } public Food sendFrag_info() { return send_info; } /*Layout Section * All Layout code about food details are down sIDe this page * */ private voID toolbarCustomization() { toolbar = (Toolbar) findVIEwByID(R.ID.foodrestoolbar); setSupportActionbar(toolbar); getSupportActionbar().setdisplayHomeAsUpEnabled(true); } private voID tabCustomization() { vIEwPager = (VIEwPager) findVIEwByID(R.ID.vIEwpager); setupVIEwPager(vIEwPager); tabLayout = (TabLayout) findVIEwByID(R.ID.tabs); tabLayout.setupWithVIEwPager(vIEwPager); setupTabIcons(); tabLayout.getTabAt(2).select(); } private voID setupTabIcons() { tabLayout.getTabAt(0).setIcon(tabIcons[0]); tabLayout.getTabAt(1).setIcon(tabIcons[1]); tabLayout.getTabAt(2).setIcon(tabIcons[2]); } private voID setupVIEwPager(VIEwPager vIEwPager) { VIEwPagerAdapter adapter = new VIEwPagerAdapter(getSupportFragmentManager()); adapter.addFragment(new OneFragment(), "desc"); adapter.addFragment(new TwoFragment(), "material"); adapter.addFragment(new ThreeFragment(), "pic"); vIEwPager.setAdapter(adapter); } class VIEwPagerAdapter extends FragmentPagerAdapter { 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); } } public int addDBfav(int ID) { sqliteDatabase sqliteDatabase; DbHelper myDbHelper = new DbHelper(this);/* try{ myDbHelper.createDatabase(); }catch (IOException e) { throw new Error("unable to create database"); }*//* myDbHelper.openDataBase(); sqliteDatabase = myDbHelper.getWritableDatabase(); Cursor cursor = sqliteDatabase.rawquery("UPDATE food SET fav=1 WHERE food_ID ==" + ID + ";", null); Log.i("successfully:", Integer.toString(cursor.getCount())); return 1;*/ myDbHelper.openDataBase(); ContentValues values=new ContentValues(); values.put("fav","1"); myDbHelper.openDataBase(); sqliteDatabase sqliteDatabase1=myDbHelper.getMyDataBase(); int part= sqliteDatabase1.update("food",values,"food_ID="+ID,null); myDbHelper.close(); Log.i("update","successful"+part); return part; }}
这是我的TwoFragment类代码:
包com.example.androID.dezcook;
import androID.content.Context;import androID.net.Uri;import androID.os.Bundle;import androID.support.annotation.Nullable;import androID.support.v4.app.Fragment;import androID.util.Log;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.ArrayAdapter;import androID.Widget.listadapter;import androID.Widget.ListVIEw;import androID.Widget.TextVIEw;import com.example.androID.dezcook.R;import java.lang.reflect.Array;import java.util.ArrayList;import java.util.List;public class TwoFragment extends Fragment { public TwoFragment() { } @OverrIDe public voID onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment VIEw v = inflater.inflate(R.layout.fragment_two, container, false); Foot_recipe foot_recipe=(Foot_recipe)getActivity(); Food food=foot_recipe.sendFrag_info(); /* ListVIEw ListVIEw=(ListVIEw)v.findVIEwByID(R.ID.show_items); ListVIEw.setAdapter();*/ String[] arr=food.getItems().split("،"); Log.i("LogArr",arr[0]); // ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(),R.layout.List_items_frag, arr); ListVIEw ListVIEw = (ListVIEw) v.findVIEwByID(R.ID.show_items); ListVIEw.setAdapter(new details_List_adapter(getActivity(),arr)); return v; }}
和TwoFragment xml代码:
<linearLayout 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" xmlns:app="http://schemas.androID.com/apk/res-auto" tools:context="com.example.androID.dezcook.TwoFragment" androID:background="@drawable/gradIEnt_background" > <!-- Todo: Update blank fragment layout --> <ListVIEw androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:ID="@+ID/show_items" androID:divIDer="@color/colorPrimaryDark" /></linearLayout>
最后是调用foot_recipe xml代码的活动:
<androID.support.design.Widget.CoordinatorLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <androID.support.design.Widget.AppbarLayout androID:background="@drawable/xml_header_background" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar"> <androID.support.v7.Widget.Toolbar androID:ID="@+ID/foodrestoolbar" androID:layout_wIDth="match_parent" androID:layout_height="?attr/actionbarSize" androID:background="@drawable/xml_header_background" app:layout_scrollFlags="scroll|enteralways" androID:layout_gravity="right" app:title=" " androID:gravity="right" > <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="foot specail" androID:layout_gravity="right" androID:textSize="25dp" androID:textStyle="bold" androID:layout_marginRight="10dp" androID:textcolor="#ffffff" androID:ID="@+ID/toolbar_Title" /> </androID.support.v7.Widget.Toolbar> <androID.support.design.Widget.TabLayout androID:ID="@+ID/tabs" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" app:tabMode="fixed" app:tabIndicatorcolor="@color/cardvIEw_dark_background" app:tabSelectedTextcolor="@color/cardvIEw_dark_background" app:tabGravity="fill"/> </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" /> <androID.support.design.Widget.floatingActionbutton androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:src="@drawable/floating_btn_heart" androID:layout_gravity="bottom|right" androID:background="@color/colorPrimary" androID:layout_margin="20dp" androID:ID="@+ID/fav_btn_heart" /></androID.support.design.Widget.CoordinatorLayout>
解决方法:
尝试添加以下代码:
ListVIEw.setontouchListener(new ListVIEw.OntouchListener() { @OverrIDe public boolean ontouch(VIEw v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: events. v.getParent().requestdisallowIntercepttouchEvent(true); break; case MotionEvent.ACTION_UP: events. v.getParent().requestdisallowIntercepttouchEvent(false); break; } v.ontouchEvent(event); return true; } });
说明,AndroID对嵌套滚动没有很好的支持,因此您需要禁用“父级”触摸管理并将事件传递给视图.
希望这个帮助
总结以上是内存溢出为你收集整理的片段中的列表视图不滚动全部内容,希望文章能够帮你解决片段中的列表视图不滚动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)