이미지 버튼을 포함해야하는 사용자 지정 어댑터가 있습니다. 그러나 getView () 메서드에 대한 재정의 구현에 대해 약간 혼란 스럽습니다. 내 이미지 버튼이 동적으로 정의되어 있으므로 코드를 사용하여 이미지 버튼을 복구 할 수 있습니다.
@Override
public View getView(int i, View view, ViewGroup viewGroup){
ImageButton ibutton = (ImageButton) getItem(i);
보기로 돌아가려면 어떻게합니까? ImageButton (다른 것과 결합되지 않음)이기 때문에 특별히 xml 파일을 만들지 않았지만 xml을 만들어야합니까? 또는 이미지 버튼 자체에서보기를 쉽게 얻을 수있는 방법이 있습니까?
getView ()에 대해 이것을 시도 할 때 어떤 이유로 이미지 버튼을 클릭 할 수 없습니다.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageButton imageButton = getItem(position);
return imageButton ;
}
다음과 같이 어댑터를 빌드하십시오.
public class ImageButtonAdapter extends BaseAdapter {
private Context mContext;
// Constructor
public ImageButtonAdapter(Context c) {
mContext = c;
}
public int getCount() {
return listCount;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageButton for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageButton imageButton ;
if (convertView == null) {
imageButton = new ImageButton (mContext);
imageButton.setLayoutParams(lp);
}
else
{
imageButton = (ImageButton ) convertView;
}
imageButton.setBackgroundColor(Color.TRANSPARENT)
return imageButton ;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다