我开发了一个安卓应用程序,其中包含列表视图与图像视图和两个文本视图,如图片attached.So我的查询是在图像上点击,而不是在列表项上。我应该导航到另一个activity.My代码,如下所示

public class MainActivity extends Activity
{
String[] animals=new String[]{"Chinkara","Redpanda","Elephant","Squirel","Langur"};
int[] images=new int[]{R.drawable.rsz_rajas_chinkara,R.drawable.rsz_rsz_sikkim_redpanda,R.drawable.rsz_jharkhand_indianelephant,R.drawable.rsz_mh_indiangiantsquirel
,R.drawable.rsz_tripura_langur};
String[] country=new String[]{"India","India","India","India","India"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lst=(ListView) findViewById(R.id.listview);
List<HashMap<String,String>> alist=new ArrayList<HashMap<String,String>>();
for(int i=0; i<5;i++)
{
HashMap<String,String> hm=new HashMap<String, String>();
hm.put("txt","Animal :" +animals[i]);
hm.put("country","Country :" +country[i]);
hm.put("image", Integer.toString(images[i]));
alist.add(hm);
}
String[] from={"image","txt","country"};
int[] to={R.id.image,R.id.txt,R.id.country};
SimpleAdapter adapter=new SimpleAdapter(getBaseContext(), alist, R.layout.listview_layout, from, to);
lst.setAdapter(adapter);
}
}发布于 2014-08-06 15:52:04
在适配器类getView()方法中尝试此代码
myImageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(context,yourActivity.class);
startActivity(i);
}
});发布于 2014-08-06 15:44:08
使用自定义列表适配器&在getView方法setonclicklistener on imageview上。参考cusom list view
发布于 2014-08-06 15:45:18
您可以在适配器中尝试此操作,而不是使用activity:
animalImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//your logic
}
});希望这能有所帮助。
https://stackoverflow.com/questions/25154800
复制相似问题