0

basically I have a text view that displays the default status of the user

        <TextView
            android:id="@+id/clickable_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:onClick="editStatus"
            android:paddingLeft="3dp"
            android:paddingRight="3dp"
            android:text="Online"/>

When I tap on this, the keyboard opens and it converts to an EditText. When this happens, there is a new button that appears that will say "Save Status". What I want is for this to do is when I tap the "Save Status" button, it will create a new text view, where the use inputted text will display. This is my code, but I've got red squigglies under new TextView(this) and linearLayout.

    private OnClickListener keyboard = new OnClickListener() {
    public void onClick(View v) {
        // Hide Keyboard
        InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(getCurrentFocus()
                .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        // Hide EditText
        EditText status = (EditText) findViewById(R.id.hidden_edit_view);
        status.setVisibility(View.GONE);
        // Get inputtes text
        String text = status.getText().toString();
        // Display text in TextView
        LinearLayout layout = (LinearLayout) findViewById(R.id.contactlist);
        TextView valueTV = new TextView(this);
        valueTV.setText(text);
        ((LinearLayout) linearLayout).addView(valueTV);
4
  • What does it say in red for the linearlayout? that seems like it should be fine. Commented Jan 28, 2013 at 0:43
  • 1
    Only thing I see wrong is that maybe you meant layout instead of linearLayout. Commented Jan 28, 2013 at 0:50
  • It said "LinearLayout cannot be resolved to a variable". It went away once I removed the ) after linearLayout, but then it told me "Syntax error, insert "AssignmentOperator Expression" to complete Expression" Commented Jan 28, 2013 at 0:54
  • Ah hah! plain layout worked great. Thanks!!! Commented Jan 28, 2013 at 0:55

1 Answer 1

2

You're going to want to reference the outer class instead by doing:

TextView valueTV = new TextView(YourActivity.this);

Since when you use just this inside the inner class, you are referencing the inner class instance, which isn't a Context, it's an OnClickListener.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, this worked for that line of code but I'm still having problems with the linearLayout part. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.