2013-01-24 28 views

回答

0

要獲得此,您需要使用自定義適配器和您的自定義佈局。

在你行的XML文件:

<TextView 
    android:id="@+id/label" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/button" /> 

在你的基地適配器,您可以再設置監聽器做一些事情:

public class MyBaseAdapter extends BaseAdapter { 

    // Some other method implementation here... 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // Initialize the convertView here... 

     LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.row_layout); 
     Button button = (Button) convertView.findViewById(R.id.button); 

     layout.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       Toast.makeText(context, "Row clicked!", Toast.LENGTH_LONG).show(); 
      } 
     }); 
     button.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       Toast.makeText(context, "Button clicked!", Toast.LENGTH_LONG).show(); 
      } 
     }); 
    }  
} 
相關問題