2014-09-25 64 views
1

我需要导航到图像上的下一页单击。使用inflator获取视图并将其分配给row.By使用行我正在访问元素“learn”,它是“dialog_layout”视图中的ImageView。现在我需要为onclicklister设置“Imgview”。我已经写了代码,但是当我点击图片视图时,它不会导航。有我在代码所做的任何错误..Imageclick onclicklistener不能使用LayoutInflater的实现

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()); 
     } 


    } 

http://i.stack.imgur.com/qWXH7.png

+0

你以后用'行'做什么? – 2014-09-25 15:47:53

回答

1

由于正在膨胀的视图已示出的对话框,你看到的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(); 
+0

我喜欢你的代码,但显示我错误我已经发布我的logcat错误以上PLZ看到它。在布局充气机它抛出异常 – 2014-09-25 16:13:19

+0

我可以看到很多警告,但没有错误 – Blackbelt 2014-09-25 16:14:27

+0

它抛出空pounit异常。 – 2014-09-25 16:17:39

相关问题