我有包含图像的列表视图,我想为每个图像打开活动。在我的代码(来自示例)中,有用于单击图像的 Toast。我想将其更改为开放活动,但我不知道如何。请帮我。这是我的代码:
public class ListOfAllAircraft extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_of_all_aircraft);
final ArrayList<ItemDetails> image_details = GetSearchResults();
final ListView lv1 = (ListView) findViewById(R.id.listV_main);
lv1.setAdapter(new ItemListBaseAdapter(this, image_details));
lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> a, final View v, final int position, final long id) {
final Object o = lv1.getItemAtPosition(position);
final ItemDetails obj_itemDetails = (ItemDetails)o;
Toast.makeText(ListOfAllAircraft.this, "You have chosen : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
}
});
}
private ArrayList<ItemDetails> GetSearchResults(){
final ArrayList<ItemDetails> results = new ArrayList<ItemDetails>();
ItemDetails item_details = new ItemDetails();
item_details.setImageNumber(1);
results.add(item_details);
item_details = new ItemDetails();
item_details.setImageNumber(2);
results.add(item_details);
item_details = new ItemDetails();
item_details.setImageNumber(3);
results.add(item_details);
item_details = new ItemDetails();
item_details.setImageNumber(4);
results.add(item_details);
item_details = new ItemDetails();
item_details.setImageNumber(5);
results.add(item_details);
item_details = new ItemDetails();
item_details.setImageNumber(6);
results.add(item_details);
return results;
}
}