1
我很新入android。我需要填充一个ListView。现在,我只是将其添加到数组中,然后尝试填充视图。它将完全从现有的数据库完成。如何从数组中填充ListView?
该列表不显示在listView小部件中。
的Main.xml
如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textColor="#0000CC"
android:background="#E8E8F0"
android:text="@string/textview1"
android:id="@+id/textview1"
android:autoText="false"/>
<ListView
android:layout_width="match_parent"
android:background="#3399FF"
android:layout_height="461dp"
android:id="@+id/metroList"
/>
</LinearLayout>
我myActivity
文件:
package com.bkane56.metrolink;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
public class MyActivity extends Activity
{
Button button;
TextView textView;
ListView listView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// button.setOnClickListener(new MyOnClickListener(this));
textView = (TextView) findViewById(R.id.textview1);
listView = (ListView) findViewById(R.id.metroList);
}
}
和我使用的arrayAdapter
填充文件:
package com.bkane56.metrolink;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
public class MetroStopList extends ListActivity {
public void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.main);
ListView metroList = (ListView) findViewById(R.id.metroList);
ArrayList<String> metroStop = new ArrayList<String>();
metroStop.add("LAMBERT MAIN TRML METROLINK STATION");
metroStop.add("LAMBERT EAST TRML METROLINK STATION");
metroStop.add("RICHMOND HEIGHTS METROLINK STATION");
metroStop.add("CLAYTON METROLINK STATION");
metroStop.add("BRENTWOOD METROLINK STATION");
metroStop.add("MAPLEWOOD METROLINK STATION");
metroStop.add("SUNNEN METROLINK STATION");
metroStop.add("FORSYTH METROLINK STATION");
metroStop.add("SHREWSBURY METROLINK STATION");
metroStop.add("NORTH HANLEY METROLINK STATION");
metroStop.add("UMSL NORTH METROLINK STATION");
//more of the same...the list is a total of 36
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, metroStop);
metroList.setAdapter(arrayAdapter);
}
}
任何帮助,将不胜感激。我相信,当我走得更远时,我会有更多的问题。
请解释一下你所看到的,当你运行你的应用程序,它从你想要什么不同之处。另外,请显示你的'AndroidManifest.xml'文件。 –