我需要在图片点击时导航到下一页。使用充气器获取视图并将其分配给行。通过使用行我正在访问元素"学习"这是" dialog_layout"中的ImageView。视图。现在我需要为那个" Imgview"设置onclicklister。我已经编写了代码但是当我点击imageview时它没有导航。我在代码中犯了任何错误..
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
try{
final Dialog dialog = new Dialog(ListViewGallery.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_layout);
Window window = dialog.getWindow();
window.setLayout(Parent.getHeight()/2, Parent.getHeight()/2);
dialog.show();
ImageView ImgView=(ImageView)findViewById(R.id.learn);
ImgView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(ListViewGallery.this,LearnLayoutAnimals.class);
startActivity(intent);
}
});
}catch(Exception e){
Log.v("dd",e.toString());
}
}
答案 0 :(得分:1)
由于在显示对话框后给视图充气,您看到的ImageView和已膨胀的ImageView是不同的对象。改变它
final Dialog dialog = new Dialog(ListViewGallery.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
View row=LayoutInflater.from(ListViewGallery.this).inflate(R.layout.dialog_layout, parent,false);
ImageView ImgView=(ImageView)row.findViewById(R.id.learn);
ImgView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(ListViewGallery.this,LearnLayoutAnimals.class);
startActivity(intent);
}
});
dialog.setContentView(row);
dialog.show();