我有列表视图,其中包含图像,我想为每个图像打开活动。 在我的代码中(来自一个例子)有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;
}
}
答案 0 :(得分:0)
onItemclicklistner
中的执行类似的操作。
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
}
}
});
也不要忘记在manifest File
。