0

我有包含图像的列表视图,我想为每个图像打开活动。在我的代码(来自示例)中,有用于单击图像的 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;
}
}
4

1 回答 1

0

in onItemclicklistner of the listview do somthing like that.

 lv1.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(final AdapterView<?> a, final View v, final int position, final long id) { 


if(position == 0){

Intent intent = new Intent (ListOfAllAircraft.java, yourOtherActivityName1.class);
startActivity(intent);
}else if(position == 1){

Intent intent = new Intent (ListOfAllAircraft.java, yourOtherActivityName2.class);
startActivity(intent);

//.... and son

}

}  
});

also don't forget to add your Activity in your manifest File.

于 2013-02-10T12:33:41.943 回答