gpt4 book ai didi

java - 将数据从 MySQL 传递到另一个 Activity 中的选取框 TextView

转载 作者:行者123 更新时间:2023-11-29 23:18:18 24 4
gpt4 key购买 nike

我将数据从 MySQL 传递到第一个 Activity 中的选取框文本并且它成功运行,但我需要将这些文本发送到另一个 Activity 而不是为我警告,请帮助

Activity 一:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dollars);
item_k001 = findViewById(R.id.item_k101);
item_k002 = findViewById(R.id.item_k102);
requestQueue = Volley.newRequestQueue(this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
final Globalv globalv = (Globalv) getApplicationContext();
try {
JSONArray jsonArray = response.getJSONArray("allegg");
String msg = "";
for (int i = 0; i < response.length(); i++) {
JSONObject respons = jsonArray.getJSONObject(i);
final String myItem_k001 = respons.getString("item_k1");
final String myItem_k002 = respons.getString("item_k2");
DollarsActivity.this.runOnUiThread(new Runnable() {
public void run() {
item_k001.setText(myItem_k001);
item_k002.setText(myItem_k002);
}
});
}
JSONObject respons2 = jsonArray.getJSONObject(0);
String id = respons2.getString("id");
globalv.setTotal_threads(Integer.parseInt(String.valueOf(id)));
} catch (JSONException e) {
e.printStackTrace();
}
}

}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", "ERROR");
}
}
);

我想将拖车文本发送到 Activity 拖车:

        //defines variables to the xml elements.
TextView tv1 = (TextView) findViewById(R.id.marqueeTextView1);
TextView tv2 = (TextView) findViewById(R.id.marqueeTextView2);
/// You can change your text here
tv1.setText("Text view");
tv2.setText("Text view ");
// We set the setSelected value to true for the shift of the texts
tv1.setSelected(true);
tv2.setSelected(true);

最佳答案

请尝试以下代码:

Activity 1

intent = new Intent(OneActivity.this, TwoActivity.class);
intent.putExtra("KEY1", myItem_k001);
intent.putExtra("KEY2", myItem_k002);
startActivity(intent);

Activity 2

//In onCreate()
Intent intent = getIntent();
text1 = intent.getStringExtra("KEY1");
text2 = intent.getStringExtra("KEY2")
tv1.setText(text1);
tv2.setText(text2);

关于java - 将数据从 MySQL 传递到另一个 Activity 中的选取框 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54899608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com