1
2package com.cfsuman.me.myapplication5;
3
4import android.support.v7.app.ActionBarActivity;
5import android.os.Bundle;
6import android.view.Menu;
7import android.view.MenuItem;
8import android.view.View;
9import android.text.Html;
10import android.widget.TextView;
11
12
13public class MainActivity extends ActionBarActivity {
14
15    @Override
16    protected void onCreate(Bundle savedInstanceState) {
17        super.onCreate(savedInstanceState);
18        setContentView(R.layout.activity_main);
19    }
20
21    public void perform_action(View v)
22    {
23        TextView tv1 = (TextView) findViewById(R.id.text_view1);
24        //define multiline by \n line separator
25        tv1.setText("Line number 1 \nLine number 2 \nLine number 3");
26
27        TextView tv2 = (TextView) findViewById(R.id.text_view2);
28        tv2.setText("Line number 1");
29        //define new line by append android system line separator
30        tv2.append(System.getProperty("line.separator"));
31        tv2.append("Line number 2");
32
33        TextView tv3 = (TextView) findViewById(R.id.text_view3);
34        String str = "Line number 1"
35                + System.getProperty("line.separator")
36                + "Line number 2";
37        //define new line by android system line separator
38        tv3.setText(str);
39
40        TextView tv4 = (TextView) findViewById(R.id.text_view4);
41        //define new line by html <br />tag
42        String str2 = "Line number 1 <br /> Line number 2";
43        //need to import android.text.Html class
44        tv4.setText(Html.fromHtml(str2));
45
46        TextView tv5 = (TextView) findViewById(R.id.text_view5);
47        tv5.setText(R.string.Multiline_Text_By_N);
48    }
49
50    @Override
51    public boolean onCreateOptionsMenu(Menu menu) {
52        // Inflate the menu; this adds items to the action bar if it is present.
53        getMenuInflater().inflate(R.menu.menu_main, menu);
54        return true;
55    }
56
57    @Override
58    public boolean onOptionsItemSelected(MenuItem item) {
59        // Handle action bar item clicks here. The action bar will
60        // automatically handle clicks on the Home/Up button, so long
61        // as you specify a parent activity in AndroidManifest.xml.
62        int id = item.getItemId();
63
64        //noinspection SimplifiableIfStatement
65        if (id == R.id.action_settings) {
66            return true;
67        }
68
69        return super.onOptionsItemSelected(item);
70    }
71}
72