douyuefei3546 2016-02-05 06:32
浏览 79
已采纳

Android SetText无法处理TextVIew,但值就在那里

Guys I am trying to set the Textview but it's not changing, the value from the database is there. i hope someone can help

here's the java code

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);


    }
}

here's the value from 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"}]
  • 写回答

5条回答 默认 最新

  • dongzhuo2371 2016-02-05 06:40
    关注

    Error in parsing Data - Please see this -

    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
    

    Here is Very Important link of parsing data - LINK

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?