Twitter Facebook Delicious Digg Stumbleupon Favorites More

Wednesday 31 January 2018

imp xml

style.xml
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>

    </style>

</resources>



DIMENSION.XML 
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>


DIMENSION W820.XML

<resources>
    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
         (such as screen margins) for screens with more than 820dp of available width. This
         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
    <dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

MAIN XML 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.londonappbrewery.destini.MainActivity"
    android:background="@drawable/background">



    <TextView
        android:id="@+id/storyTextView"
        android:text="@string/T1_Story"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="24sp"
        android:textColor="#ffffffff"
        />

    <Button
        android:id="@+id/buttonTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/T1_Ans1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="61dp"
        android:background="#e74c3c"
        android:textColor="#ecf0f1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="15sp"
        />

    <Button
        android:id="@+id/buttonBottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/T1_Ans2"
        android:layout_alignParentBottom="true"
        android:layout_alignLeft="@+id/buttonTop"
        android:layout_alignStart="@+id/buttonTop"
        android:layout_alignRight="@+id/buttonTop"
        android:layout_alignEnd="@+id/buttonTop"
        android:background="#3498db"
        android:textColor="#ecf0f1"
        android:textSize="15sp"/>



</RelativeLayout>

Share:

Thursday 18 January 2018

quiz app type 1

STEPS : FIRST SET ALL XML FILES FOR ALL

COLOUR.XML  , DIMESION .XML ,STRING.XML , STYLE.XML

  MAIN ACTIVITY .JAVA

package com.example.viraj.quiz;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import static android.widget.Toast.makeText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
//ToDo Declear constant Here   100/13 =8 approx or u can declear below mquestion bank also
//final int PROGRESS_BAR_INCREMENT=8;
    //ToDo Declear membar variable Here
// Member variables accessible in all the methods of the MainActivity:
    Button mTrueButton, mFalseButton;
    TextView mQuestionTextView;
    TextView mScoreTextView;
    ProgressBar mProgressBar;
    int mIndex;
    int mScore;
    int mQuestion;
    Toast mToastMessage;


    //ToDo Uncommnnet to create question bank
// Create question bank using the TrueFalse class for each item in the array
    @NonNull
    private TrueFalse[] mQuestionBank = new TrueFalse[]{
            new TrueFalse(R.string.question_1_1, true),
            new TrueFalse(R.string.question_2, true),
            new TrueFalse(R.string.question_3, true),
            new TrueFalse(R.string.question_4, true),
            new TrueFalse(R.string.question_5, true),
            new TrueFalse(R.string.question_6, false),
            new TrueFalse(R.string.question_7, true),
            new TrueFalse(R.string.question_8, false),
            new TrueFalse(R.string.question_9, true),
            new TrueFalse(R.string.question_10, true),
            new TrueFalse(R.string.question_11, false),
            new TrueFalse(R.string.question_12, false),
            new TrueFalse(R.string.question_13, true)
    };
//int[] myIndArray=new int[] {2,4,6};
    // math ceil ek function he jo conversion ka kamm kar raha hee double ko singlie me
// Declaring constants here. Rather than a fixed number, choosing to make it a function
// of the length of the question bank (the number of questions)
final int PROGRESS_BAR_INCREMENT = (int) Math.ceil(100.0 / mQuestionBank.length);

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

        mTrueButton = findViewById(R.id.true_button);
        mFalseButton = findViewById(R.id.false_button);
        mQuestionTextView = findViewById(R.id.question_text_view);
        mScoreTextView = findViewById(R.id.score);
        mProgressBar = findViewById(R.id.progress_bar);

//int element= myIndArray[1];
//type is truefalse  ,,,  name is first question

//TrueFalse firstQuestion=mQuestionBank[mIndex];
        //mQuestion =firstQuestion.getQuestionID();
        mQuestion = mQuestionBank[mIndex].getQuestionID();
        mQuestionTextView.setText(mQuestion);

        mTrueButton.setOnClickListener(this);
        mFalseButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.true_button:
              //  Toast.makeText(getApplicationContext(), "TRUE", Toast.LENGTH_SHORT).show();
                updateQuestion();
                checkAnswer(true);
                break;
            case R.id.false_button:
            //    Toast.makeText(getApplicationContext(), "FALSE", Toast.LENGTH_SHORT).show();
                updateQuestion();
                checkAnswer(false);
                break;

        }
    }

    private void updateQuestion() {
        // This takes the modulus. Not a division. ye bhi use kar sakte he
        mIndex=(mIndex+1)%mQuestionBank.length;
        mQuestion=mQuestionBank[mIndex].getQuestionID();
        mQuestionTextView.setText(mQuestion);



         //Present an alert dialog if we reach the end.
        if(mIndex == 0) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle("Game Over");
            alert.setCancelable(false);
            alert.setMessage("You scored " + mScore + " points!");
            alert.setPositiveButton("Close Application", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
            alert.show();
        }

        mProgressBar.incrementProgressBy(PROGRESS_BAR_INCREMENT);
        mScoreTextView.setText("Score " + mScore + "/" + mQuestionBank.length);
    }

    private void checkAnswer(boolean userSelection) {

        boolean correctAnswer = mQuestionBank[mIndex].isAnswer();
//
        // Can cancel the Toast message if there is one on screen and a new answer
       // has been submitted.
        if (mToastMessage != null) {
           mToastMessage.cancel();
        }

        if(userSelection == correctAnswer) {
            mToastMessage = makeText(getApplicationContext(), R.string.correct_toast, Toast.LENGTH_SHORT);
            mScore = mScore + 1;

        } else {
            mToastMessage = Toast.makeText(getApplicationContext(), R.string.incorrect_toast, Toast.LENGTH_LONG);
        }

        mToastMessage.show();
    }

    // This callback is received when the screen is rotated so we can save the 'state'
    // of the app in a 'bundle'.
    @Override
    public void onSaveInstanceState(Bundle outState){
        super.onSaveInstanceState(outState);

        outState.putInt("ScoreKey", mScore);
        outState.putInt("IndexKey", mIndex);
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

TRUEFALSE.JAVA

package com.example.viraj.quiz;

/**
 * Created by viraj on 1/11/2018.
 */
// This is the model class that represents a single quiz question.
public class TrueFalse {


    private int mQuestionID;
    private boolean mAnswer;
//getter and setter method auto generate
    // This is the constructor that will be called when a new quiz question is created.
    public TrueFalse(int questionResourceID, boolean trueOrFalse) {
        mQuestionID = questionResourceID;
        mAnswer = trueOrFalse;
    }
    //getter and setter  auto generate
    // This method gives us access to info stored in the (private) question id.
    public int getQuestionID() {
        return mQuestionID;
    }
    //getter and setter  auto generate
    // This method gives us access to info stored in the (private) mAnswer.
    public boolean isAnswer() {
        return mAnswer;
    }

    // Not actually using the setters at the moment. Users are not creating questions.

//    public void setQuestionID(int questionID) {
//        mQuestionID = questionID;
//    }

//    public void setAnswer(boolean answer) {
//        mAnswer = answer;
//    }

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
XML FILE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     tools:context="com.example.viraj.quiz.MainActivity"
    android:background="@color/colorPrimaryDark"
    android:orientation="vertical"
        >


    <TextView
        android:id="@+id/question_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:gravity="center"
        android:padding="20dp"
        android:text="@string/question_1_1"
        android:textColor="@color/colourText"
        android:textStyle="bold"
        android:textSize="30sp"
        />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_centerHorizontal="true"
        android:layout_above="@id/score"

        android:gravity="center"
        android:padding="20dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/true_button"

            android:layout_width="150dp"
            android:layout_height="wrap_content"
            style="@style/buttonStyle"
            android:text="@string/true_button"
            android:background="@color/colourTrueButton"/>

        <Button
            android:id="@+id/false_button"

            android:layout_width="150dp"
            android:layout_height="wrap_content"

            style="@style/buttonStyle"
            android:text="@string/false_button"
            android:background="@color/colourFalseButton"/>

    </LinearLayout>

    <ProgressBar
        android:id="@+id/progress_bar"

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:indeterminate="false" />

    <TextView
        android:id="@+id/score"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_above="@id/progress_bar"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"

        android:textColor="@color/colourText"
        android:textStyle="bold"
        android:textSize="25sp"
        android:text="@string/initial_score"
        android:padding="10dp"/>
</RelativeLayout>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

COLOUR.XML

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="colourText">#F5F5F5</color>
    <color name="colourTrueButton">#CDDC39</color>
    <color name="colourFalseButton">#2196F3</color>
</resources>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

STYLE.XML
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <!-- Both buttons share a similar style attibutes so we can put them here -->
    <style name="buttonStyle" parent="Widget.AppCompat.Button.Colored">
        <item name="android:textSize">20sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/colourText</item>
        <item name="android:layout_margin">@dimen/button_spacing_margin</item>
    </style>
</resources>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DIMESSION

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="button_spacing_margin">4dp</dimen>
</resources>



Share:

Monday 15 January 2018

arti type app new line solution

<resources>
    <string name="app_name">Del</string>
    <string name="hindi">

        <html> जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडाजय देव !\n
\n
जेजुरगड पर्वत शिवलिंगाकार, मृत्युलोकी दुसरे कैलास शिखर,\n
नाना परि ती रचना रचली अपार,\n
त्रयेस्थळी नांदे स्वामी शंकर....जय देव !\n
जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडाजय देव !\n
\n
मणि-मल्ल दैत्य प्रबळ तो झाला,\n
देव-गण-गंधर्व कापति त्याला,\n
हाती तलवार, खडग, त्रिशूळ, भाला,\n
आदि शक्ती म्हाळसा घेउन संगतिला....जय देव !\n
जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडाजय देव !\n
\n
चंपा शष्ठी दिवशी अवतार धरिशी,\n
मणि-मल्ल दैत्यांचा संहार करीशी,\n
चरणी पृष्टि वरति खडग़ स्थापिशी,\n
अंति वर देउनी त्यास मुक्ति दे देशी.....जय देव !\n
जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडाजय देव !\n
\n
मणि-मल्ल दैत्य मर्दुनी मल्हारी,\n
देवा संकट पडता राहे जेजूरी,\n
अर्धांगी म्हाळसा शोभे सुंदरी,\n
देवा ठाव मागे दास नरहरि....जय देव !\n
जय देव, जय देव, जय शिव मार्तंडा…\n
हरी मदन मल्हारी तूची प्रचंडाजय देव !\n</html>
    </string>
</resources>


or plz check

TextView txtSubTitle = (TextView)findViewById(r.id.txtSubTitle);
txtSubTitle.setText(Html.fromHtml(getResources().getString(R.string.sample_string)));
Share:

Tuesday 9 January 2018

xylopone android app


MAIN ACTIVITY

package com.example.viraj.xylopone_music;

import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.lang.ref.PhantomReference;

public class MainActivity extends AppCompatActivity {
//HELPFUL CONSTANT
    private final int NR_OF_SIMULATANEOUS_SOUND=7;
    private final float LEFT_VOLUME=1.0f;
    private final float RIGHT_VOLUME=1.0f;
    private final int NO_LOOP=0;
    private final int PRIORITY=0;
    private final float NORMAL_PLAY_RATE=1.0f;

    //TODO add MEMBER VARIABLE HERE
    private SoundPool mSoundPool;
    private int nASoundID;
    private int nBSoundID;
    private int nCSoundID;
    private int nDSoundID;
    private int nESoundID;
    private int nFSoundID;
    private int nGSoundID;
    private int nHSoundID;



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

        //todo create a sound
        mSoundPool=new SoundPool(7, AudioManager.STREAM_MUSIC,0);

        //todo load and get the id to identify the sound
        nASoundID=mSoundPool.load(getApplicationContext(),R.raw.note6_a,1);
        nBSoundID=mSoundPool.load(getApplicationContext(),R.raw.note7_b,1);
        nCSoundID=mSoundPool.load(getApplicationContext(),R.raw.note1_c,1);
        nDSoundID=mSoundPool.load(getApplicationContext(),R.raw.note2_d,1);
        nESoundID=mSoundPool.load(getApplicationContext(),R.raw.note3_e,1);
        nFSoundID=mSoundPool.load(getApplicationContext(),R.raw.note4_f,1);
        nGSoundID=mSoundPool.load(getApplicationContext(),R.raw.note5_g,1);
        nHSoundID=mSoundPool.load(getApplicationContext(),R.raw.lst,1);
        //todo add the play method triggered by button

    }
    //todo Add the play method triggered by the button
    public void playC(View v)
    {
       // mSoundPool.play(nASoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);   same hi he demo he niche valal
mSoundPool.play(nCSoundID,1.0f,1.0f,0,0,1.0f);
    }
    public void playD(View v)
    {
        mSoundPool.play(nDSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playE(View v)
    {
        mSoundPool.play(nESoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playF(View v)
    {
        mSoundPool.play(nFSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playG(View v)
    {
        mSoundPool.play(nGSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playA(View v)
    {
        mSoundPool.play(nASoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playB(View v)
    {
        mSoundPool.play(nBSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
    public void playH(View v)
    {
        mSoundPool.play(nHSoundID,LEFT_VOLUME,RIGHT_VOLUME,PRIORITY,NO_LOOP,NORMAL_PLAY_RATE);
    }
}

XML FILE

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.viraj.xylopone_music.MainActivity">

    <Button
        style="@style/KeyStyle"
        android:id="@+id/c_key"
        android:background="@color/red"
        android:onClick="playC"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:background="@color/orange"
        android:id="@+id/d_key"
        android:onClick="playD"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <Button style="@style/KeyStyle"
        android:id="@+id/e_key"
        android:background="@color/yellow"
        android:onClick="playE"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <Button style="@style/KeyStyle"
        android:id="@+id/f_key"
        android:background="@color/green"
        android:onClick="playF"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:id="@+id/g_key"
        android:background="@color/turquoise"
        android:onClick="playG"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:id="@+id/a_key"
        android:background="@color/blue"
        android:onClick="playA"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="25dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:id="@+id/b_key"
        android:background="@color/purple"
        android:onClick="playB"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button style="@style/KeyStyle"
        android:background="@color/red"
        android:id="@+id/h_key"
        android:onClick="playH"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>

COLOUR
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>

    <color name="colorAccent">#FF4081</color>

    <color name="colorPrimaryDark">#000000</color>
    <color name="red">#e74c3c</color>
    <color name="orange">#e67e22</color>
    <color name="yellow">#f1c40f</color>
    <color name="turquoise">#1abc9c</color>
    <color name="green">#2ecc71</color>
    <color name="blue">#3498db</color>
    <color name="purple">#9b59b6</color>

</resources>

STYLE
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="KeyStyle">
        <item name="android:layout_weight">1</item>
        <item name="android:layout_marginTop">3dp</item>
        <item name="android:layout_marginBottom">3dp</item>
    </style>

</resources>




Share:

Monday 8 January 2018

Android App Magic Ball 8

Android App Magic Ball 8 


package com.example.viraj.magic_8_ball;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
private Button rollbutton;
private ImageView imageview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rollbutton=(Button)findViewById(R.id.id_button);
        imageview=(ImageView)findViewById(R.id.id_image);
final int [] arrayimage={
        R.drawable.ball1,
        R.drawable.ball2,
        R.drawable.ball3,
        R.drawable.ball4,
        R.drawable.ball5
};
        rollbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Random random=new Random();
                int randomnogene=random.nextInt(arrayimage.length);//or int randomnogene=random.nextInt(5);
                imageview.setImageResource(arrayimage[randomnogene]);
            }
        });
    }
}



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.viraj.magic_8_ball.MainActivity"
    android:background="#4FC3F7">

    <TextView
        android:id="@+id/text_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:text="@string/txttitle"
        android:textAlignment="center"
        android:textColor="#E91E63"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/id_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        app:srcCompat="@drawable/ball1" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/id_image"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="41dp"
        android:shadowColor="#FF5722"
        android:textColor="#E91E63"
        android:textStyle="bold"
        android:text="@string/buttonname" />
</RelativeLayout>




Share:

Saturday 6 January 2018

Dice App random number based

package com.example.viraj.diceapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
    Button rollbutton;
    ImageView leftimage, rightimage;

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

        rollbutton = (Button) findViewById(R.id.rollbutton);
        leftimage = (ImageView) findViewById(R.id.leftdice);
        rightimage = (ImageView) findViewById(R.id.rightdice);

        final int[] dicearray = {
                R.drawable.dice1,
                R.drawable.dice2,
                R.drawable.dice3,
                R.drawable.dice4,
                R.drawable.dice5,
                R.drawable.dice6,
        };

        rollbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                
                Random random_nu_generator = new Random();
                int random_no = random_nu_generator.nextInt(6);
                
                leftimage.setImageResource(dicearray[random_no]);

                int random_no_2 = random_nu_generator.nextInt(6);

                rightimage.setImageResource(dicearray[random_no_2]);
            }
        });
    }
}



xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/newbackground"
    tools:context="com.example.viraj.diceapp.MainActivity">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="250dp">

        <ImageView
            android:id="@+id/logoimage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            app:srcCompat="@drawable/dicee_logo" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/leftdice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/dice3" />

        <ImageView
            android:id="@+id/rightdice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/dice1" />
    </LinearLayout>

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/rollbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/button_text"
        android:textStyle="bold"
        android:background="#3F51B5"
        android:textColor="#FFEB3B"/>

    </RelativeLayout>
</LinearLayout>


Share:

RANDOM NUMBER GENERATOR CODE ANDROID



package com.example.viraj.diceapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
    Button rollbutton;
    ImageView leftimage , rightimage;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rollbutton=(Button) findViewById(R.id.rollbutton);
        leftimage=(ImageView)findViewById(R.id.leftdice);
        rightimage=(ImageView)findViewById(R.id.rightdice);
        rollbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // Toast.makeText(getApplicationContext(),"HELLO",Toast.LENGTH_LONG).show();
                Random random_nu_generator=new Random();
               int random= random_nu_generator.nextInt(1999);
                Toast.makeText(getApplicationContext(),"RANDOM NO IS = " + "" +random,Toast.LENGTH_LONG).show();

            }
        });
    }
}

Share:

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab