Isitha Subasinghe Isitha Subasinghe - 2 months ago 9
Java Question

Android Programming with Java, how to use R.id

studio to create an android app that adds a string from an editText with an id of input and displays it into

textView
with an id of output. But

EditText input = EditText(findViewById(R.id.input));


and

TextView output = TextView(findViewById(R.id.output));


doesnt work as it says Method call expected. Any kind of help would be great, thankyou.

package com.example.toshb.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity
{
private Model model;
public MainActivity() {model = new Model();}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void processInput(View view)
{
EditText input = EditText(findViewById(R.id.input));
TextView output = TextView(findViewById(R.id.output));
model.addString(editText.getText().toString());
output.setText(model.getList());
input.setText("");
}
}

Answer Source

You need to add proper declaration of EditText And TextView . Before write a code please have a look here:
https://developer.android.com/index.html

EditText input = (EditText)findViewById(R.id.input);
TextView output =(TextView)findViewById(R.id.output);
model.addString(input.getText().toString());