Sunday, January 24, 2016

How to add sound with ImageSwitcher

Respected developers , I m creating app of alphabets , I am unable to add sound with imageswitcher,
I want when user press next button , It should give next image with its sound

my code is
Code:

I have sound in Row folder name a,b,c
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ViewSwitcher.ViewFactory;

public class New extends ActionBarActivity implements ViewFactory {

       
        ImageSwitcher is;
        int [] imgid = {R.drawable.i1,
                                        R.drawable.i2,
                                        R.drawable.i3,
                                        R.drawable.i4};
        Button prev, next;
        int count =0;
       
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.poetry);
               
               

                final Button switchact = (Button) findViewById(R.id.btn1);
                switchact.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                                Intent act2 = new Intent(view.getContext(), MainActivity.class);
                                startActivity(act2);
                               
                        }
                });
               
                is = (ImageSwitcher)findViewById(R.id.imageSwitcher1);
                prev = (Button)findViewById(R.id.button1);
                next = (Button)findViewById(R.id.button2);
                is.setFactory(this);
                is.setInAnimation(this, android.R.anim . slide_in_left);
                is.setOutAnimation(this, android.R.anim.slide_out_right);
       
                prev.setOnClickListener(new View.OnClickListener() {
                       
                        @Override
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                        if(count>0)
                                        {
                                                count--;
                                                try{
                                                                is.setImageResource(imgid[count]);
                                                        }
                                                catch(Exception e)
                                                {
                                                        e.printStackTrace();
                                                }
                                        }
                                        else
                                        {
                                                Toast.makeText(New.this, "First", Toast.LENGTH_LONG).show();
                                        }
                        }
                });
                next.setOnClickListener(new View.OnClickListener() {
                       
                        @Override
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                if(count                                 {
                                       
                                                                       
                                        try{
                                                is.setImageResource(imgid[count]);
                                        }
                                catch(Exception e)
                                {
                                        e.printStackTrace();
                                }
                                        count++;
                                       
                                }
                                else
                                {
                                        Toast.makeText(New.this, "Last", Toast.LENGTH_LONG).show();
                                }
                        }
                });
               
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.main, menu);
                return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
                // Handle action bar item clicks here. The action bar will
                // automatically handle clicks on the Home/Up button, so long
                // as you specify a parent activity in AndroidManifest.xml.
                int id = item.getItemId();
                if (id == R.id.action_settings) {
                        return true;
                }
                return super.onOptionsItemSelected(item);
        }

public boolean appnot(View v){
         
          Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
          sharingIntent.setType("text/plain");
          String shareBody = "http://ift.tt/1ntrrm6;;
          sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "I found a best Urdu Learing App Please try");
          sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
          startActivity(Intent.createChooser(sharingIntent, "Share via"));
               
                            return false;
            }
public void about(View v){
         
          {
                  new AlertDialog.Builder(this)
                  .setTitle(R.string.app_about)
                 
              .setNegativeButton(R.string.str_ok,
                  new DialogInterface.OnClickListener()
              {
                          public void onClick(DialogInterface dialoginterface, int i)
                          {
                          }
                          })
                          .show();
                          }

                 
          }



     
public void exit(View v){
         
          {
                  new AlertDialog.Builder(this)
                  .setTitle(R.string.app_exit)
                  .setIcon(R.drawable.ic_launcher)
                  .setMessage(R.string.app_exit_message)
              .setNegativeButton(R.string.exit,
                  new DialogInterface.OnClickListener()
                  {
                  public void onClick(DialogInterface dialoginterface, int i)
                  {
                  System.exit(0);
                  }
                  })
                  .show();
                 
                 
                  }
  }
 

        @Override
        public View makeView() {
                // TODO Auto-generated method stub
                                ImageView iv = new ImageView(this);
                                iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                iv.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
                               
                                return iv;
                        }

                }

please help me about it


via xda-developers http://ift.tt/1ORew3X

IFTTT

Put the internet to work for you.

Turn off or edit this Recipe

No comments:

Post a Comment