I am trying to create a simple listview with items in them. I have done this ton of times but this time for some reason, the scrolling does not work. I am using basic adapter to display items but still it does not work. Been stuck on this for 6 hours. Any help would be greatly appreciated. The ListView used in the fragment does not scroll.
The Fragment that has the listview:
public class BlankFragment extends Fragment {
String[] itemsList = {"uguga", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "g", "h", "i", "j", "k"};
View mView;
ListView mListView;
ArrayAdapter<String> mAdapter;
public BlankFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_blank, container, false);
mListView = (ListView) mView.findViewById(R.id.newsFeedListView);
mAdapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_dropdown_item_1line, android.R.id.text1, itemsList);
mListView.setAdapter(mAdapter);
return mView;
}
}
fragment_blank.xml
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:divider="#000000"
android:id="@+id/newsFeedListView"
xmlns:android="http://schemas.android.com/apk/res/android"/>
activity_main.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/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content_frame"
tools:context=".MainActivity" />
<ListView
android:layout_width="250dp"
android:layout_height="match_parent"
android:id="@+id/drawerItemsListView"/>
</android.support.v4.widget.DrawerLayout>
Main Activity.java
public class MainActivity extends ActionBarActivity {
DrawerLayout mDrawerLayout;
ListView mDrawerListView;
NewsFeedFragment mNewsFeedFragment;
ActionBar mActionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initReferences();
initFragments();
initProperties();
}
private void initProperties() {
mActionBar.setBackgroundDrawable(new ColorDrawable(0xFF326CBB));
}
private void initFragments() {
mNewsFeedFragment = NewsFeedFragment.newInstance();
getSupportFragmentManager().beginTransaction().add(R.id.content_frame, new BlankFragment()).commit();
}
private void initReferences() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mDrawerListView = (ListView) findViewById(R.id.drawerItemsListView);
mActionBar = getSupportActionBar();
}
}
将ListView
高度设置为"match_parent"
。
All Right. Solved this. The ListView on the MainActivity was taking all the input touches since i did not specify a gravity for that. Once i added
android:layout_gravity="start"
to the MainActivity ListView, i was able to scroll.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.