Reputation: 424
Ok so I've looked at other posts with the same problem, but still can't figure out what I'm doing wrong. Here's my code:
ListView list = (ListView) getView().findViewById(R.id.listView);
String[] stringArray = new String[] { "Bright Mode", "Normal Mode","Bright Mode",
"hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode",
"hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode",
"hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","Bright Mode",
"hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode","end", "Bright Mode", "Normal Mode","Bright Mode",
"hey Mode","Bright Mode", "Normal Mode","Bright Mode", "Normal Mode", "end2" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(getView().getContext(), R.layout.document_list_view, stringArray);
list.setAdapter(modeAdapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Toast.makeText(getView().getContext(), "Clicked", Toast.LENGTH_LONG).show();
}
});
Clicking works just fine, but the content goes off screen and it won't let me scroll. Here's my XML. It's not inside a scrollview or anything.
document_list_view:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/listText"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:textColor="@color/black">
</TextView>
layout of the page:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="1000dp"
android:layout_height="600dp">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
Upvotes: 0
Views: 681
Reputation: 424
Found this issue, it was because I was extending a class that places everything inside a scrollview. Don't put listviews inside scrollviews
Upvotes: 2
Reputation: 527
If you are using a custom view for each list item, you need to use a Custom Adapter for the list view. You will need something like this
public class CustomAdapter extends ArrayAdapter<String>{
List<String> items;
....
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.document_list_view, null);
}
String item = (String) items.get(position);
if (item != null) {
TextView text= (TextView) v.findViewById(R.id.listText);
if (text!= null) {
text.setText(item);
}
}
return v;
}
And set this object as an adapter to your list.
Upvotes: 0
Reputation: 17140
change your page layout to just be the list view that will match the size of its parent in this case the window decor.
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
Upvotes: 0