伙计们,我正在尝试设置Textview
,但它没有改变,数据库中的值在那里。我希望有人能帮帮忙
这是java代码
public class Announcement_Details extends AppCompatActivity{
private static final String GET_URL = "http://XXX";
private ProgressDialog pDialog;
TextView id,title,content,date;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lv_view);
id = (TextView)findViewById(R.id.tv_id);
title = (TextView)findViewById(R.id.tv_title);
content = (TextView)findViewById(R.id.tv_content);
date = (TextView)findViewById(R.id.tv_date);
getAnnouncementDetails();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.refresh) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void getAnnouncementDetails() {
StringRequest postRequest = new StringRequest(Request.Method.POST, GET_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
JSONArray data = jsonResponse.getJSONArray("announcement_data");
Log.d("Announcement Data", ""+data);
id.setText(data.getString(0));
title.setText(data.getString(1));
content.setText(data.getString(2));
date.setText(data.getString(3));
}catch (Exception e) {
e.printStackTrace();
}
pDialog.dismiss();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}
) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
// the POST parameters:
params.put("id", getIntent().getStringExtra("id"));
return params;
}
};
pDialog = new ProgressDialog(Announcement_Details.this);
pDialog.setMessage("Getting Announcements Details.");
pDialog.show();
Volley.newRequestQueue(getApplication()).add(postRequest);
}
}
这是logcat的值
02-05 01:28:35.861 4004-4004/com.example.wackyroad.internannouncement D/Announcement Data﹕ [{"announcement_title":"Sample Title Here","announcement_content":"Sample Content","announcement_date":"2016-02-04"}]
最佳答案
解析数据时出错-
请看这个-
title.setText(data.getJSONObject(0).getString("announcement_title"));//announcement_title
content.setText(data.getJSONObject(0).getString("announcement_content"));//announcement_content
date.setText(data.getJSONObject(0).getString("announcement_date"));//announcement_date
这是解析数据的非常重要的链接-LINK
关于java - Android SetText在TextVIew上不起作用,但是值在那里,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35217654/