انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
اجرای چندین صوت در یک لیست ویو (در برنامه نویسی اندروید)

اجرای چندین صوت در یک لیست ویو (در برنامه نویسی اندروید)

#10
با درود.کدهای برنامه را به شکل زیر درآوردم.ولی هنوز هم آیتم های لیست ویو کار نمیکند.فک میکنم از لحاظ فنی مشکل دارد.یک نگاهی بیاندازید.کلا یک کلاس جاوا و2 xml ذارد که paste کرده ام.

کد پی‌اچ‌پی:
package com.kelidetan.customlistview;

import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class 
MainActivity  extends ListActivity  {
     MediaPlayer mediaPlayer;
     SeekBar seek_bar;
        Button play_buttonpause_button;
       
        Handler seekHandler 
= new Handler();
    public ListView lv;
    
    int 
[] music={R.raw.abc,R.raw.asd,R.raw.asx,R.raw.my_file}; 
    
    public String number_of_keys
;
    public String[] my_items = {"key_1",
                                  "key_2",
                                  "key_3",
                                  "key_4",
                                  "key_5",
                                  "key_6",
                                  "key_7",
                                  "key_8",
                                  "key_9",
                                  "key_10",
                                  "key_11",
                                  "key_12",
                                  "key_13",
                                  "key_14",
                                  "key_15",
                                  "key_16",
                                  "key_17",
                                  "key_18",
                                  "key_19",
                                  "key_20"
                                 };

    @Override
    protected void onCreate
(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
           
                setListAdapter
(new MyAdapter(this, 
                               android
.R.layout.simple_list_item_1, 
                               R
.id.textView1,
                               my_items));    
                
            
                
        lv 
getListView();
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            
public void onItemClick(AdapterView<?> parent, final View view,
                int position, long id) {                        
                
                
                
                mediaPlayer=MediaPlayer.create(getApplicationContext(), music[position]); 
                 mediaPlayer.start();
                
                    
            }

        });
    }

    
    
    private class MyAdapter extends ArrayAdapter<String>{

        
        
        public MyAdapter(Context context, int resource, int textViewResourceId,
                String[] strings) {
            super(context, resource, textViewResourceId, strings);
            // TODO Auto-generated constructor stub
        }
        
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View row = inflater.inflate(R.layout.sot, parent, false);
            
            String stringName = "string_key_" + String.valueOf(position+1); 
            int string_res_ID = getResources().getIdentifier(stringName,"string",getPackageName());
            String my_string = getResources().getString(string_res_ID);
            TextView tv = (TextView) row.findViewById(R.id.textView1);
            tv.setText(my_string);
            
            
            seek_bar = (SeekBar) row.findViewById(R.id.seek_bar);
            play_button = (Button)  row.findViewById(R.id.play_button);
            pause_button = (Button)  row.findViewById(R.id.pause_button);
            seek_bar.setMax(mediaPlayer.getDuration());
            seekUpdation();
            return row;
            
        }
        

    }
    

    
    
     Runnable run = new Runnable() {

            @Override
            public void run() {
                seekUpdation();
            }
        };

        public void seekUpdation() {

            seek_bar.setProgress(mediaPlayer.getCurrentPosition());
            seekHandler.postDelayed(run, 1000);
            seek_bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                
                @Override
                public void onStopTrackingTouch(SeekBar seek_bar) {
                    // TODO Auto-generated method stub
                    
                }
                
                @Override
                public void onStartTrackingTouch(SeekBar seek_bar) {
                    // TODO Auto-generated method stub
                    
                }
                
                @Override
                public void onProgressChanged(SeekBar seek_bar, int progress, boolean fromUser) {
                    if(fromUser){ 
                        mediaPlayer.seekTo(progress); 
                        seek_bar.setProgress(progress);
                    }
                    
                }
            });
        }

     
        
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 
            if(fromUser){ 
                mediaPlayer.seekTo(progress); 
                seekBar.setProgress(progress);
            }
        }
        
        
        @Override
        public void onBackPressed() {
            mediaPlayer.stop();
            finish();
        }
          


    


کد پی‌اچ‌پی:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     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"
    
     >

    <SeekBar
        android:id="@+id/seek_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/play_button"
        android:layout_alignParentTop="true"
        android:layout_marginTop="27dp" />

    <Button
        android:id="@+id/play_button"
        android:layout_width="120dp"
        android:layout_height="60dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/seek_bar"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="19dp"
        android:gravity="center"
        android:text="Play" />

    <Button
        android:id="@+id/pause_button"
        android:layout_width="120dp"
        android:layout_height="60dp"
        android:layout_alignBaseline="@+id/play_button"
        android:layout_alignBottom="@+id/play_button"
        android:layout_alignRight="@+id/seek_bar"
        android:text="Pause" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/play_button"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="24dp"
        android:text="TextView" />
 
</RelativeLayout>


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
      
</LinearLayout> 
پاسخ


پیام‌های این موضوع
RE: اجرای چندین صوت در یک لیست ویو - توسط داش بهروز - ۱۳۹۴/۰۸/۱۶, ۰۲:۳۶ ق.ظ
RE: اجرای چندین صوت در یک لیست ویو (در برنامه نویسی اندروید) - توسط kama90 - ۱۳۹۴/۰۸/۲۰, ۰۱:۱۴ ق.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان