English 中文(简体)
单一名单问题
原标题:Android list view problem

我对我的名单上有问题——我试图增加一个头脑和脚眼,但似乎都出现在名单上的上下。 此外,在我开车时,冻结了几秒。

我的守则如下:

        LayoutInflater inflater = getLayoutInflater();
    View header = inflater.inflate(R.layout.header_row, (ViewGroup) findViewById(R.id.header_layout_root));
    header.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClassName("com.visualdenim.schooltraq", "com.visualdenim.schooltraq.Add_Class");
            startActivity(i);
        }});
    getListView().addHeaderView(header, null, true);

    LayoutInflater footerinflater = getLayoutInflater();
    View footer = footerinflater.inflate(R.layout.footer_row, (ViewGroup) findViewById(R.id.header_layout_root));
    getListView().addFooterView(footer, null, false);

    classes = new ArrayList<Course>();

    this.cla = new CLA(this, R.layout.row, classes);   

    setListAdapter(this.cla);

    cla.notifyDataSetChanged();

最好的答案是:

最佳回答
问题回答

Heres a similar thing i did with a list view, with a button at the bottom and a spinner at the top, you might be able to modify it to suit your app. XML layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:id="@+id/top_control_bar">
    <Spinner android:id="@+id/sort_by" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:entries="@array/default_sorts" />
</RelativeLayout>
<LinearLayout android:id="@+id/bottom_control_bar"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">
    <Button android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Add Item" />
</LinearLayout>
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
    android:layout_height="0dip" android:choiceMode="multipleChoice"
    android:layout_below="@id/top_control_bar" android:layout_above="@id/bottom_control_bar"></ListView>
<TextView android:id="@android:id/empty" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="@string/main_empty_list"
    android:layout_below="@id/top_control_bar"android:layout_above="@id/bottom_control_bar" />
</RelativeLayout>

Java Code:

// myList.java
package com.test.listview;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class myList extends ListActivity 
{
/** Called when the activity is first created. */
public void onCreate(Bundle bundle) 
{
    super.onCreate(bundle);
    // Create an array of Strings, that will be put to our ListActivity

    String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
            "Ubuntu", "Solaris", "Android", "iPhone", "Linux", "Windows7",
            "Eclipse", "Suse", "Ubuntu", "Solaris", "Android", "iPhone" };
    setContentView (R.layout.main);
    ListView listView = getListView();
    ArrayAdapter a = new ArrayAdapter <String>(this, android.R.layout.simple_list_item_single_choice, names);
    setListAdapter(a);

    }
}

Strings.xml:

// strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, myList!</string>
<string name="app_name">listview</string>
<string-array name="default_sorts">
    <item>fooboo</item>
    <item>asdfgh</item>
    <item>qwerty</item>
    <item>346346</item>
    <item>hjkgaf</item>
    <item>asdfas</item>
    <item>vbncvn</item>
    <item>dfgrdf</item>
    <item>hjkkmb</item>
    <item>fdghgv</item>
</string-array>
<string name="main_empty_list">foo</string>
</resources>




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签