2015-11-03 60 views
0

IMPOSIBLE访问在OnCreate中我把这个片段:机器人负载片段做的ImageView

if(internet == true){ 
     Fragment fragment = null; 
     fragment = new PasarProjectos(); 

     /*if(esLandscape == true){ 
      contenedor_salvado = findViewById(R.id.contenedor_info); 
     }*/ 

     if (fragment != null) { 

      FragmentManager fm = getSupportFragmentManager(); 
      Bundle args = new Bundle(); 
      args.putBoolean("esLandscape", esLandscape); 
      fragment.setArguments(args); 
      fm.beginTransaction().add(R.id.container, fragment).commit(); 

     } 
     findViewById(R.id.imageView17).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       startActivity(new Intent(PasarProjNoMenu.this, InicioNoLogin.class)); 
      } 
     }); 
    }else{ 
     startActivity(new Intent(PasarProjNoMenu.this, InicioNoLogin.class)); 
    } 

和完成的的onCreate

的方法后来我打电话,我尝试本地化另一种观点的另一种方法

public void ensenarProjMismaPantalla(String id_s) { //un inflate rellenando los datos y punto 

    Log.d("La acción ","rellenar campo primero"); 

    ImageView imageView = (ImageView) findViewById(R.id.fotoProj); 

} 

我知道的imageview是连续的; y在屏幕上,因为我可以在应用程序运行时看到它,但该应用程序会抛出nullpointerexception错误

+0

请写在那里你调用这个方法:'ensenarProjMismaPantalla()' – walkmn

+0

进入片段“PasarProjectos.java” –

+0

我离开的代码放到一个答案 –

回答

0

解决,进入分片我所说的方法是这样的:

((PasarProjNoMenu)context).ensenarProjMismaPantalla(int_parameter); 

的问题是,当我尝试调用同一个类的2倍,在相同的活动。

Thx为您的时间。

0

我打电话从片段中的主要活动,我知道我可以

public void anadirFragmentConDatos(
     final String id_s, String nombre_s, String ticket_s, String porfinanciar_s, String imagen_s, final int pos){ 
    //generamos el inflater para poder añadir el hijo 
    LinearLayout parent = (LinearLayout) view.findViewById(R.id.ListadoPrj); 
    LayoutInflater layoutInflater = (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    final View addView = layoutInflater.inflate(R.layout.fragment_pre_project, null); 

    addView.setId(Integer.parseInt(id_s)); 

    addView.setOnTouchListener(
      new View.OnTouchListener() { 
       @Override 
       public boolean onTouch(View v, MotionEvent event) { 
        if (esLandscape == false) { 
         switch (event.getAction() & MotionEvent.ACTION_MASK) { 
          case MotionEvent.ACTION_UP: 
           //Toast.makeText(getActivity(),"Me ha pulsado",Toast.LENGTH_SHORT).show(); 
           SociosInversores si = new SociosInversores(); 

           String Uid = si.Uid; 

           Intent intent = new Intent(getActivity(), ProjectFullScreen.class); 
           Bundle bundle = new Bundle(); 

           bundle.putString("Uid", Uid); 
           bundle.putString("Pid", id_s); 

           intent.putExtras(bundle); 

           startActivity(intent); 

         } 
        }else{ 
         switch (event.getAction() & MotionEvent.ACTION_MASK) { 
          case MotionEvent.ACTION_UP: 
           //cargar en el lateral 
           PasarProjNoMenu ppnm = new PasarProjNoMenu(); 
           ppnm.ensenarProjMismaPantalla(id_s); 

         } 
        } 


        return true; 
       } 
      } 
    ); 

    //añadimos el view 
    parent.addView(addView); /*the rest of the method*/} 

我正确地声明类,我想。