errang
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!
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!
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.
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.
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));
}
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
on what you observe with regards to the undesired behavior