0

好的,所以我查看了其他具有相同问题的帖子,但仍然无法弄清楚我做错了什么。这是我的代码:

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();

        }
    }); 

单击工作正常,但内容会离开屏幕,它不会让我滚动。这是我的 XML。它不在滚动视图或任何东西内。

文档列表视图:

<?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>

页面布局:

<?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>
4

3 回答 3

2

发现这个问题,这是因为我正在扩展一个将所有内容都放在滚动视图中的类。不要将列表视图放在滚动视图中

于 2013-06-27T13:36:21.240 回答
0

如果您为每个列表项使用自定义视图,则需要为列表视图使用自定义适配器。你需要这样的东西

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;
}

并将此对象设置为您列表的适配器。

于 2013-06-26T21:39:14.350 回答
0

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>
于 2013-06-26T21:03:24.267 回答