开发者

Launching a ListActivity from another Activity

开发者 https://www.devze.com 2023-04-02 15:06 出处:网络
I am creating an application that saves GPS coordinates; I have created a button which launches a new Activity to display, as a list all the save coordinates. The program crashes a soon as I hit the b

I am creating an application that saves GPS coordinates; I have created a button which launches a new Activity to display, as a list all the save coordinates. The program crashes a soon as I hit the button, here is what I am doing.

class 1:

        public void openLatLonData(View view)
    {
        Intent intent = new Intent(this, GpsDataList.class);
        ArrayList<String> allLocalStrings = new ArrayList<String>();
        for(int i =0; i< AllLocals.size();i++)
        {
            allLocalStrings.add(AllLocals.get(i).getLat());
            allLocalStrings.add(AllLocals.get(i).getLon());
        }
        intent.putStringArrayListExtra("data", allLocalStrings);
        startActivity(intent);
    }

This method calls the new activity:

public class GpsDataList extends ListActivity

{

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle bundleIn) 
{
    super.onCreate(bundleIn);
    Intent intent = getIntent();
    ArrayList<String> listData = new ArrayList<String>();

    listData = intent.getStringArrayListExtra("data");

    this.setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, lis开发者_运维技巧tData));
  getListView().setTextFilterEnabled(true);

  //finish();

}

}

the button contains the following XML:

    <Button android:layout_height="wrap_content" 
android:text="Show Collected Data" 
android:id="@+id/view_lat_lon_data" 
android:layout_width="wrap_content"
android:onClick="openLatLonData">
</Button>

And I have added a new .xml file named gpsdatalist.xml under the res/layout folder:

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

</LinearLayout>

Lastly the manifest contains this: .

I believe I have all the pieces in play- Hopefully someones see the mistake Thanks in advance guys!


Did you define the activity in the AndroidManifest.xml file? Anyway, your best clue resides in the logcat of your exception. You will solve it in 2 seconds after cheking the logcat.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号