尝试添加到我的OnClickListener中,因此当我从Firestore中单击文档时,它会从中检索文本并将其放在下一个活动的TextView中。这是我的代码如下:
@Override
public void onItemClick(Session documentSnapshot, int position) {
String session = documentSnapshot.getDocumentID();
startActivity(new Intent(SessionManagement.this, QRGenerator.class)
.putExtra("module_code", documentSnapshot.Id));
Toast.makeText(SessionManagement.this, "Session ID: " +session,Toast.LENGTH_SHORT).show();
}
});
}
这是我要在其上显示文本的活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qrgenerator);
text = (EditText) findViewById(R.id.edit_text_generate);
gen_btn = (Button)findViewById(R.id.GENERATE);
image = (ImageView) findViewById(R.id.imageQR);
gen_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text2Qr = text.getText().toString().trim();
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try {
BitMatrix bitMatrix = multiFormatWriter.encode(text2Qr, BarcodeFormat.QR_CODE,200,200);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
image.setImageBitmap(bitmap);
} catch (WriterException e){
e.printStackTrace();
}
getIncomingIntent();
}
});
}
private void getIncomingIntent(){
if (getIntent().hasExtra("module_code")){
String moduleCode = getIntent().getStringExtra("module_code");
setModuleCode(moduleCode);
}
}
private void setModuleCode(String moduleCode){
TextView module = findViewById(R.id.edit_text_generate);
module.setText(moduleCode);
}
}
答案 0 :(得分:0)
这是答案:我在错误的地方打电话给getIncomingIntent
FrameLayout