2014-07-16 86 views
0

我的適配器類是這樣的:的Android的ListView BaseAdapter

public View getView(int i, View view, ViewGroup viewGroup) { 
    View satirView; 
    satirView = mInflater.inflate(R.layout.adapter, null); 
    TextView ad = (TextView) satirView.findViewById(R.id.ad); 

    TextView soyad = (TextView) satirView.findViewById(R.id.soyad); 
    TextView tarih = (TextView) satirView.findViewById(R.id.tarih); 
    Button buton = (Button) satirView.findViewById(R.id.icon); 

    police po = policem.get(i); 
    ad.setText(po.getAd()); 
    soyad.setText(po.getNo()); 
    tarih.setText(po.getTarih()); 


    return satirView; 
} 

和我的MainActivity類別是這樣的:

listView = (ListView) findViewById(R.id.list); 

    // Defined Array values to show in ListView 
    List<police> values = new ArrayList<police>(); 
    values.add(new police("ss","kk","123")); 
    values.add(new police("ss","kk","456")); 
    values.add(new police("ss","kk","789")); 
    values.add(new police("ss","kk","147")); 
    values.add(new police("ss","kk","258")); 
    values.add(new police("ss","kk","753")); 

    adabter adapt = new adabter(this,values); 
    listView.setAdapter(adapt); 

我有按鈕,但我不能使用onclickedlistener梅託德..我應該怎麼辦? 我在哪裏寫作?

+0

如果你想設置的點擊監聽器?在整個列表項目上還是隻在您的視圖中的按鈕? –

回答

0

,如果你想在整個列表項目上的按鈕單擊只沒有,那麼你只寫你的適配器類中getView代碼()之類的方法:

buton .setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 

      } 
     }); 

,如果你需要點擊整個列表事件項目,那麼你應該在你的活動中編寫代碼。

0

試試這個:

 ViewHolder holder = (ViewHolder) satirView.getTag(); 
     holder.buton.setOnClickListener(new OnClickListener() { 


     @Override 
     public void onClick(View v) { 

     //do your stuffs here 

     }   
    }); 
相關問題