Listview 列表视图未在片段中滚动
我创造了这个抽屉。选择一个项目时,它将显示一个带有列表视图的片段。该列表视图没有滚动 代码如下: 主要活动Listview 列表视图未在片段中滚动,listview,android-fragments,Listview,Android Fragments,我创造了这个抽屉。选择一个项目时,它将显示一个带有列表视图的片段。该列表视图没有滚动 代码如下: 主要活动 private NavigationDrawerFragment mNavigationDrawerFragment; private CharSequence mTitle; FrameLayout frameLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate
private NavigationDrawerFragment mNavigationDrawerFragment;
private CharSequence mTitle;
FrameLayout frameLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frameLayout = (FrameLayout)findViewById(R.id.container);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
switch (position) {
case 1:
break;
case 2:
Fragment f = new ChordFragment();
fragmentTransaction.replace(R.id.container, f).commit();
break;
case 3:
break;
case 4:
break;
}
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.navi_home);
break;
case 2:
mTitle = getString(R.string.navi_favourite);
break;
case 3:
mTitle = getString(R.string.navi_new);
break;
case 4:
mTitle = getString(R.string.navi_rateus);
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.main, menu);
restoreActionBar();
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
CHORDFRAGMENT
public class ChordFragment extends Fragment {
ListView mChordList;
ArrayList<TCDataModel> list = new ArrayList<TCDataModel>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/** Inflating the layout for this fragment **/
View v = inflater.inflate(R.layout.fragment_chord, null);
mChordList = (ListView) v.findViewById(R.id.lv_chords);
for (int i = 0; i < 20; i++) {
TCDataModel mTCDataModel = new TCDataModel();
mTCDataModel.setSongName("Song Name " + i);
mTCDataModel.setMuviName("Muvi Name " + i);
list.add(mTCDataModel);
}
mChordList.setAdapter(new ChordListAdapter(getContext(), list));
return v;
}
公共类ChordFragment扩展了片段{
ListView-mChordList;
ArrayList=新建ArrayList();
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
/**正在为该片段扩展布局**/
视图v=充气机。充气(R.layout.fragment_chord,空);
mChordList=(列表视图)v.findViewById(R.id.lv_和弦);
对于(int i=0;i<20;i++){
TCDataModel mTCDataModel=新的TCDataModel();
mTCDataModel.setSongName(“歌曲名”+i);
mTCDataModel.setMuviName(“Muvi名称”+i);
list.add(mTCDataModel);
}
setAdapter(新的ChordListAdapter(getContext(),list));
返回v;
}
}
主要活动
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="@+id/tool_bar"
layout="@layout/toolbar">
</include>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" /></android.support.v4.widget.DrawerLayout>
片段\u和弦
<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"
<ListView
android:id="@+id/lv_chords"`enter code here`
android:layout_width="match_parent"
android:clickable="true"
android:layout_height="match_parent" />`</LinearLayout>`
如果您按如下方式修改主\u activity.xml文件,则它工作正常:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
如果您按如下方式修改主\u activity.xml文件,则它工作正常:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
如果您已经解释了OP代码的错误以及您所更改的内容,这将非常有用。现在,读者必须上下上下查看,试图了解差异是什么,并尝试猜测这些更改是否与类似但不完全相同的问题相关。如果您已经解释了OP代码的错误以及您所更改的内容,这将非常有帮助。现在,读者必须上下、上下查看,以了解差异是什么,并尝试猜测这些变化是否与类似但不完全相同的问题相关。