2012-02-07 36 views
0

我有列表视图的listAdapter,我已经在custome adapter.i设置录制按钮已经把代码的holder.record click事件里面像与纪录保持者服装适配器问题

holder.record.setBackgroundResource(R.drawable.record_green); 

的同时用户触摸该按钮的设置背景。但我的问题是,当我触摸特定列表项按钮此图像在另一个列表项申请

这里是代码::

holder.record.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 

      if (isplaying2 == true) { 

      } else 
      { 
       if (b_Flag_Record_or_not == true) { 
       } else { 
        try { 

         holder.record.setBackgroundResource(R.drawable.record_green); 
         b_Flag_Record_or_not = true; 
         b_play_or_not = true; 

         flag_stop_position = position; 
         AuthHandler dataHandler = new AuthHandler(); 
         AuthDataset dataset = dataHandler 
           .getParsednewJobdtl_DataSet(); 

         System.out.println("dataset.getint1();" 
           + dataset.getint1()); 
         // Login l = new Login(); 
         String str_useid = RequestTo[position]; 
         recorder = new AudioRecorder("/audiometer/shanesh" 
           + RequestId[position] + "-" + str_useid); 
         start_or_not = true; 
         recorder.start(); 
         Toast.makeText(context, "Start Recording", Toast.LENGTH_LONG).show(); 
         CountDownTimer countDowntimer = new CountDownTimer(
           120000000, 1000) { 
          public void onTick(long millisUntilFinished) { 
          } 

          public void onFinish() { 
           try { 
            Toast.makeText(
              context, 
              "Stop recording Automatically ", 
              Toast.LENGTH_LONG).show(); 
            recorder.stop(); 
           } catch (Exception e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
           } 
          } 
         }; 
         countDowntimer.start(); 

        } catch (IOException e) { 
         Writer writer = new StringWriter(); 
         PrintWriter printWriter = new PrintWriter(writer); 
         e.printStackTrace(printWriter); 
         String s = writer.toString(); 

        }catch (Exception e) { 

        } 
       } 

      } 
     } 
    }); 

更新::

public class ListViewAdapter extends BaseAdapter { 

public static Activity context; 

String title[]; 
String description[]; 
String RequestId[]; 
String Folderpath[]; 
String RequestTo[]; 

boolean b_Flag_Record_or_not = false; 
boolean b_upload_or_not = false; 
boolean start_or_not = false; 
boolean start_play = false; 
boolean upload_or_not = false; 
boolean b_play_or_not = false; 
boolean isplaying2 = false; 

Thread welcomeThread; 
int glob_position; 
MediaPlayer mPlayer2; 
int flag_stop_position; 
AudioRecorder recorder; 
AnimationDrawable frameAnimation, frameAnimation_play; 
private static String mFileName = null; 
private MediaRecorder mRecorder = null; 
private MediaPlayer mPlayer = null; 
Recording login = new Recording(); 
ViewHolder holder; 
MediaPlayer MP_completeRequest = new MediaPlayer(); 

public ListViewAdapter(Activity context, String[] title, 
     String[] description, String[] req_id, String[] FolderPath, 
     String[] Arr_RequestTo) { 
    super(); 
    this.context = context; 
    this.title = title; 
    this.description = description; 
    this.RequestId = req_id; 
    this.Folderpath = FolderPath; 
    this.RequestTo = Arr_RequestTo; 
} 

public int getCount() { 
    // TODO Auto-generated method stub 
    return title.length; 
} 

public Object getItem(int position) { 
    // TODO Auto-generated method stub 
    return null; 
} 

public long getItemId(int position) { 
    // TODO Auto-generated method stub 
    return 0; 
} 

private class ViewHolder { 
    TextView txtViewTitle; 
    TextView txtViewDescription; 
    Button record, stop, play, upload; 
} 

public View getView(final int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 

    LayoutInflater inflater = context.getLayoutInflater(); 
    glob_position = position; 
    if (convertView == null) { 
     convertView = inflater.inflate(R.layout.listitem_row, null); 
     holder = new ViewHolder(); 
     holder.txtViewTitle = (TextView) convertView 
       .findViewById(R.id.textView1); 
     holder.txtViewDescription = (TextView) convertView 
       .findViewById(R.id.textView2); 
     holder.record = (Button) convertView.findViewById(R.id.record); 

     holder.stop = (Button) convertView.findViewById(R.id.stop); 
     holder.play = (Button) convertView.findViewById(R.id.play1); 
     holder.upload = (Button) convertView 
       .findViewById(R.id.audio_upload); 
     /* set button image */ 



     convertView.setTag(holder); 
    } else { 
     holder = (ViewHolder) convertView.getTag(); 
    } 
    try { 

     Typeface face = Typeface.createFromAsset(context.getAssets(), 
       "fonts/tahoma.ttf"); 
     holder.txtViewTitle.setTypeface(face); 

     holder.txtViewTitle.setText(title[position]); 
     holder.txtViewDescription.setText(description[position]); 


    } catch (ArrayIndexOutOfBoundsException e) { 
     e.printStackTrace(); 
    } 
+0

粘贴完整的代码。 – jeet 2012-02-07 07:07:10

+0

我有更新 – 2012-02-07 07:11:30

回答

0

请参阅支架用于重复使用适配器视图的意见,因此,如果一个屏幕可以显示5项次,第6项将重用项目1号的观点,因此持有人。

使用ListView.onItemClickListener代替holder.record.setOnClickListener(),或视设定背景为getView方法,我在编辑方法getVIew代码:getView方法

public class ListViewAdapter extends BaseAdapter { 

public static Activity context; 

String title[]; 
String description[]; 
String RequestId[]; 
String Folderpath[]; 
String RequestTo[]; 

boolean b_Flag_Record_or_not = false; 
boolean b_upload_or_not = false; 
boolean start_or_not = false; 
boolean start_play = false; 
boolean upload_or_not = false; 
boolean b_play_or_not = false; 
boolean isplaying2 = false; 

Thread welcomeThread; 
int glob_position; 
MediaPlayer mPlayer2; 
int flag_stop_position; 
AudioRecorder recorder; 
AnimationDrawable frameAnimation, frameAnimation_play; 
private static String mFileName = null; 
private MediaRecorder mRecorder = null; 
private MediaPlayer mPlayer = null; 
Recording login = new Recording(); 
ViewHolder holder; 
MediaPlayer MP_completeRequest = new MediaPlayer(); 

public ListViewAdapter(Activity context, String[] title, 
     String[] description, String[] req_id, String[] FolderPath, 
     String[] Arr_RequestTo) { 
    super(); 
    this.context = context; 
    this.title = title; 
    this.description = description; 
    this.RequestId = req_id; 
    this.Folderpath = FolderPath; 
    this.RequestTo = Arr_RequestTo; 
} 

public int getCount() { 
    // TODO Auto-generated method stub 
    return title.length; 
} 

public Object getItem(int position) { 
    // TODO Auto-generated method stub 
    return null; 
} 

public long getItemId(int position) { 
    // TODO Auto-generated method stub 
    return 0; 
} 

private class ViewHolder { 
    TextView txtViewTitle; 
    TextView txtViewDescription; 
} 

public View getView(final int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 

    LayoutInflater inflater = context.getLayoutInflater(); 
    glob_position = position; 
    if (convertView == null) { 
     convertView = inflater.inflate(R.layout.listitem_row, null); 
     holder = new ViewHolder(); 
     holder.txtViewTitle = (TextView) convertView 
       .findViewById(R.id.textView1); 
     holder.txtViewDescription = (TextView) convertView 
       .findViewById(R.id.textView2); 

     /* set button image */ 



     convertView.setTag(holder); 
    } else { 
     holder = (ViewHolder) convertView.getTag(); 
    } 
    try { 

     Typeface face = Typeface.createFromAsset(context.getAssets(), 
       "fonts/tahoma.ttf"); 
     holder.txtViewTitle.setTypeface(face); 

     holder.txtViewTitle.setText(title[position]); 
     holder.txtViewDescription.setText(description[position]); 


    } catch (ArrayIndexOutOfBoundsException e) { 
     e.printStackTrace(); 
    } 

    Button record = (Button) convertView.findViewById(R.id.record); 

    Button stop = (Button) convertView.findViewById(R.id.stop); 
    Button play = (Button) convertView.findViewById(R.id.play1); 
    Button upload = (Button) convertView 
       .findViewById(R.id.audio_upload); 
    record.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 

     if (isplaying2 == true) { 

     } else 
     { 
      if (b_Flag_Record_or_not == true) { 
      } else { 
       try { 

        record.setBackgroundResource(R.drawable.record_green); 
        b_Flag_Record_or_not = true; 
        b_play_or_not = true; 

        flag_stop_position = position; 
        AuthHandler dataHandler = new AuthHandler(); 
        AuthDataset dataset = dataHandler 
          .getParsednewJobdtl_DataSet(); 

        System.out.println("dataset.getint1();" 
          + dataset.getint1()); 
        // Login l = new Login(); 
        String str_useid = RequestTo[position]; 
        recorder = new AudioRecorder("/audiometer/shanesh" 
          + RequestId[position] + "-" + str_useid); 
        start_or_not = true; 
        recorder.start(); 
        Toast.makeText(context, "Start Recording", Toast.LENGTH_LONG).show(); 
        CountDownTimer countDowntimer = new CountDownTimer(
          120000000, 1000) { 
         public void onTick(long millisUntilFinished) { 
         } 

         public void onFinish() { 
          try { 
           Toast.makeText(
             context, 
             "Stop recording Automatically ", 
             Toast.LENGTH_LONG).show(); 
           recorder.stop(); 
          } catch (Exception e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
          } 
         } 
        }; 
        countDowntimer.start(); 

       } catch (IOException e) { 
        Writer writer = new StringWriter(); 
        PrintWriter printWriter = new PrintWriter(writer); 
        e.printStackTrace(printWriter); 
        String s = writer.toString(); 

       }catch (Exception e) { 

       } 
      } 

     } 
    } 
}); 
+0

所以我做什么请编辑我的代码.. – 2012-02-07 07:19:58

+0

有什么变化,我还没有找到....我有比较完整的代码,但没有发现变化...请帮我 – 2012-02-07 07:49:08

+0

希望现在可以看到 – jeet 2012-02-07 07:59:29