textView does not change text

Asked

Viewed 26 times

0

I created a Fragment in Android Studio, and in this Fragment there is an imageView and a textView which I want to edit by code. but the two do not change...

public class HomeFragment extends Fragment {

private static String userkey;

public HomeFragment() {
    // Required empty public constructor
}

public static HomeFragment newInstance(String key){
    final HomeFragment homeFragment = new HomeFragment();

    userkey=key;

    return homeFragment;
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_home,container,false);

    ImageView imageView = view.findViewById(R.id.qrImage);
    TextView textView = view.findViewById(R.id.userCode);

    QRCodeWriter writer = new QRCodeWriter();
    try{
        BitMatrix bitMatrix = writer.encode(userkey, BarcodeFormat.QR_CODE,512,512);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        Bitmap bmp = Bitmap.createBitmap(width,height,Bitmap.Config.RGB_565);
        for(int z=0; z<width;z++){
            for(int k=0; k<height; k++){
                bmp.setPixel(z, k, bitMatrix.get(z, k) ? Color.BLACK : Color.WHITE);
            }
        }
        imageView.setImageBitmap(bmp);
    }
    catch (WriterException e) {
        e.printStackTrace();
    }

    textView.setText(userkey);

    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_home, container, false);


}

1 answer

1

To work, you need to give the Return in the view, not the inflate, getting:

textView.setText(userkey);

// Inflate the layout for this fragment
return view;}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.