Link to home
Start Free TrialLog in
Avatar of errang
errangFlag for Afghanistan

asked on

ListViews on Android

Hey,

        I was trying to use ListViews to show a menu, and when one of the options was clicked, jump to a different activity, and contain some variables so the activity can carry out the operation.

I did get the ListView to work, because it was just placing an ArrayList inside the adapter, and it would work fine... but I'm having problems making it switch to the new activity properly...

I tried searching for tutorials on this, but I don't exactly know what I'm looking for...

Appreciate any help on this!
Avatar of for_yan
for_yan
Flag of United States of America image

Perhaps you'd post some part of your code and be a little bit more specific
on what you observe with regards to the undesired behavior
Avatar of errang

ASKER

I can't post the entire code... but I've rewritten it to a "hello world" level problem, so I can understand things more clearly.

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class Vehicle extends Activity {
	public void onCreate(Bundle savedBundleInstance) {
		super.onCreate(savedBundleInstance);
		setContentView(R.layout.vehicle);
		ArrayList<String> strArr = new ArrayList<String>();

	   	strArr.add("one");
		strArr.add("two");
		strArr.add("three");
		strArr.add("four");

		TextView tv = new TextView(this);
		tv.setText("TestView");
		ListView lv = (ListView)findViewById(R.id.listView);
		lv.addHeaderView(tv);
		lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strArr));
	}
}

Open in new window


I figured out how to figure out what choice was clicked... but I have no idea how to launch a different activity that would do what its supposed to do.
ASKER CERTIFIED SOLUTION
Avatar of aciuica
aciuica
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Dejan Pažin
Dejan Pažin
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial