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 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析