Breaking News
Loading...

Scrambled Words Application

9:25 PM
mail.xml
-----------

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<TextView
      android:layout_width="fill_parent"
     android:layout_height="wrap_content"
    android:text="Scrambled:"
    android:textSize="30dip"
    android:layout_marginTop="30dip" />
   <EditText
   android:id="@+id/scw"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_marginTop="20dip"
   android:layout_marginLeft="100dip"
   android:layout_marginRight="10dip" />
   <TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Guess:"
    android:textSize="30dip"
    android:layout_marginTop="120dip"  />
   <EditText
   android:id="@+id/gus"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_marginTop="120dip"
   android:layout_marginLeft="100dip"
   android:layout_marginRight="10dip"  />
<Button 
android:id="@+id/cli"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="check"
android:textSize="30dip"
android:layout_marginLeft="50dip"
android:layout_marginRight="50dip"
android:layout_marginTop="230dip" />
</RelativeLayout>


------------------------------------------------------------------
Scrambled.java
----------------------
package sra.get;
import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Scrambled extends Activity implements OnClickListener
{
    /** Called when the activity is first created. */
        EditText e1,e2;
          String names[]={"sravan","anil","dharan","rajesh","ramu","rajkumar","subrmanyam","satish","lavanya","madhavi","vasundhara","lakshmi"};
          String snames[]={"narvsa","nial","nahdra","hesajr","umra","akarmuj","msuaybnram","aitshs","ylaaavn","aamdvih","aaadhnrsuv","ahiklms"};
          Button b;
          TextView tv;
          int rv;
    @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        e1=(EditText)findViewById(R.id.scw);
        e2=(EditText)findViewById(R.id.gus);
        e1.setSelected(false);
        Random r= new Random();
        rv=r.nextInt(names.length);
          e1.setText(snames[rv]);
        e2.setSelection(0);
          tv= new TextView(this);
        b=(Button)findViewById(R.id.cli);
        this.b.setOnClickListener(this);
       
    }
   
    public void onClick(View v)
    {
       
       //String s1=e1.getText().toString();
       String s2=e2.getText().toString();
       if(s2.equals(names[rv]))
     tv.setText(" ok");
       else
           tv.setText(" sorry");
       setContentView(tv);
       
    }
   
}


0 komentar:

Post a Comment

 
Toggle Footer