gpt4 book ai didi

android - 无法从数据库中获取数据并有意传递

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:18 25 4
gpt4 key购买 nike

我在第一个 Activity 中从 MySQL 请求数据

protected Void doInBackground(String... params) {
// TODO Auto-generated method stub

String url = "http://myhost/app/get.php?id=" + name_id;

JSONArray data;
try {
resultServer = getJSONUrl(url);
data = new JSONArray(resultServer);

MyArrList = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map;

for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, Object>();
map.put("id", (String)c.getString("id"));
map.put("name", (String)c.getString("name"));
map.put("description", (String)c.getString("description"));

MyArrList.add(map);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

然后像这样将此信息传递给另一个 Activity

Intent newActivity = new Intent(act1.this,act2.class);

newActivity.putExtra("Name", Name);
newActivity.putExtra("tableDescription", description);
startActivity(newActivity);
finish();

在下一个 Activity 中我得到这样的信息

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

String textDescription, name;
TextView txtView;

txtView = (TextView) findViewById(R.id.text);
txtView = (TextView) findViewById(R.id.name);

Intent intent= getIntent();
textDescription = getIntent().getStringExtra("description");
((TextView)findViewById(R.id.text)).setText(textDescription+"");
name = getIntent().getStringExtra("Name");
((TextView)findViewById(R.id.name)).setText(name+"");
}

所以在第二个 Activity 中 Name 在那里,但是 textDescription 显示为 null,我确定数据库中的该列中有文本。

最佳答案

你的问题出在

 newActivity.putExtra("tableDescription", description);

textDescription = getIntent().getStringExtra("description");

应该是

textDescription = getIntent().getStringExtra("tableDescription");

关于android - 无法从数据库中获取数据并有意传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27897765/

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