jeudi 13 août 2015

How do I send an activity's layout to a non activity class to change an imageView?

so I'm trying to send a layout that has an imageview that I want to replace with an image picked by the user, then send that whole layout to a new activity to be displayed but I'm having trouble. It's returning null at the line below where I indicated. Please help!

So this is the class that recieves the layout and changes the image of the imageView.

public class TestingClass
{

    public static int displayImage(Activity activity, int id, String path)
    {
        ImageView img = (ImageView) activity.findViewById(id);//This is where it's returning null
        img.setImageBitmap(BitmapUtility.decodeSampledBitmapFromResource(path,500,500));
        return id;
    }
}

Then displayImage will be called in this activity.

public class UserCard extends Activity
{

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_card);

    }


    public int sendstuff()
    {
        String testing2 = cardFactory.getInstance().getValue().grabImagePathString;//Getting the image path the user selected
        return TestingClass.displayImage(this,R.layout.user_card,testing2);
    }

Finally, I want that layout (with the ImageView changed by the user) in my main layout.

public class MyActivity extends Activity implements View.OnClickListener {

@Override
protected void onCreate(Bundle savedInstanceState)//Does Load METHODS in order!!!!
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    ButterKnife.inject(this);
    UserCard user = new UserCard();
    al = new ArrayList<>();
    al.add("max");
     arrayAdapter = new ArrayAdapter<>(this, user.sendstuff(), R.id.helloText, al);
    flingContainer.setAdapter(arrayAdapter);

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire