Saturday 27 September 2014

DAY 8 : REMEMBER SYNTAX TO CALL AN ACTION IN ACTIVITY

HELLO BUDDS!!!

WELCOME BACK HERE!!!

I HAVE SOLUTION FOR ALL THE ACTIONS WHICH WILL BE CALL IN ACTIVIT'Y/IES!!!


1. Register Activity : [AndroidManifest.xml]
            <activity android:name=".SecondActivity" android:label="@string/app_name">

      </activity>

2. Create An Intent : [<activityClassNAme.java>]
      startActivity(new Intent("second"));

3. Button: [<activityClassNAme.java>]
            Button mybtn=(Button)findViewById(R.id.button);

4. ClickListener:[<activityClassNAme.java>]
      1. after "extends Activity" "implements OnClickListene"
     
      2. mybtn.setOnClickListener(this);
      // outside function & inside activity class
      public void onClick(View v) {
            startActivity(new Intent("second"));     
      }

5. SecondActivity:[<activityClassNAme.java>]
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.second);
            }

6. ListView:
            1.  import android.app.ListActivity;
      2. extends ListActivity{  //not Activity this time
      3. String str[]={"One","Two"};
          setListAdapter(new ArrayAdapter<String>(this,           R.layout.main,R.id.label,str));
      4. [in "main.xml" at "res->layout->"]
            <TextView  …..
             /TextView>

7. Toast
      Toast.makeText(this,”Your Message”,Toast.Length_Short).show();

8. Alert
      AlertDialog.Builder alert = new AlertDialog.Builder(AlertDemoActivity.this);
      alert.setTitle("My Alert of Tsunami");
      alert.setMessage("No need to worry about Tsunami. It's Safe.");
      alert.setIcon(R.drawable.geekslab_icon);
      alert.show();


All the codes can be found in given applications

0 comments:

Post a Comment

DON'T BE SELFISH !!! SHARE IT !!!