簡體   English   中英

無法解析方法setText-AndroidStudio

[英]Cannot resolve method setText - AndroidStudio

預先抱歉,這是我使用android完成的第一個項目。

我正在嘗試使php文件中的文本出現,但是setText表示無法解析該方法。 我確定這里有很多事情做錯了,但setText是目前唯一的錯誤。

private String itemTitle;
private String itemDate;
private String itemContent;

Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
    public void onResponse(JSONObject response) {

        NewsRecord record = new NewsRecord();
        try {
            record.title = response.getString("title");
            record.shortInfo = response.getString("short_info");
        } catch (JSONException e) {
            e.printStackTrace();
        }

        itemTitle.setText(record.title);
        itemDate.setText(record.date);
        itemContent.setText(record.shortInfo);

    }
    };

        Response.ErrorListener errorListener = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        };


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Intent intent = getIntent();
        int recordId = intent.getIntExtra("record_id", 0);

        String url = "http://www.tnt.com/projects/newsfeed/getList.php";

        new JsonObjectRequest(url, null, listener, errorListener);


    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

String沒有setText()方法。 您可能正在尋找擴展TextView東西。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM