Friday 26 September 2014

Runtime Set TextView Example

package com.example.helloworld;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        TextView txt_hello=new TextView(this);
        txt_hello.setText("Hello World");
        Toast.makeText(getApplicationContext(), "Hello is not world",Toast.LENGTH_LONG).show();
        setContentView(txt_hello);
       
        return true;
    }
   
}
 App like this:



No comments:

Post a Comment