2011-09-15 48 views
0

我在我的屏幕中顯示了一個動態列表視圖。在列表視圖中,eack行中有兩個按鈕。我想要處理兩個按鈕上的點擊事件。我在列表視圖中有50-60行。現在當我點擊任何一行的按鈕時,它會佔據第一行的列表視圖的位置。所以我的問題是我必須得到點擊行的完美位置。我用baseadapter,但我只能夠處理每行上的一個點擊事件。Android的listview位置和點擊事件處理問題

所以給這個問題一些提示。

+0

把你的適配器代碼。 – Ronnie

+0

@harsh http://pareshnmayani.wordpress.com/tag/android-custom-listview-例子/ –

+0

@harsh在這個例子中,你可以在每個listview項目中設置你的控件,並且位置將決定處理clickevent –

回答

1

公共類MovietListAdapter延伸BaseAdapter {

公衆詮釋getCount將(){ 返回_languagechange; }

public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

公共視圖getView(最終詮釋位置,查看convertView, 的ViewGroup父){ 視圖V; LayoutInflater vi =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.movi​​elistdesign,null); ImageView iv =(ImageView)v.findViewById(R.id.icon);

 iv.setImageDrawable(mLoader.getDrawble(position)); 
     iv.setPadding(1, 1, 1, 1); 
     ImageView star = (ImageView) v.findViewById(R.id.starrating); 

star.setOnClickListener(新View.OnClickListener(){

  public void onClick(View v) { 
       Bundle bundle = new Bundle(); 
       bundle.putString("param1", mLoader.ds1.movie_ids[position]); 
       bundle.putString("param2", 
         mLoader.ds1.movie_titles[position]); 
       bundle.putString("param3", 
         mLoader.ds1.movie_thumbnailarray[position]); 
       bundle.putString("param4", 
         mLoader.ds1.movie_descarray[position]); 
       bundle.putString("param5", 
         mLoader.ds1.movie_rating[position]);