1

実行時にビューを作成する代わりに、xml レイアウトを使用せずにアイテムを入力したい.これが私のgetView()方法です。

 public View getView(final int position, View convertView, ViewGroup parent) {

    EditText v ;    

    if(convertView ==null)
    {
        v = new EditText(mContext);
        convertView = v;
        convertView.setTag(R.string.edittext_child, v);

    }
    else
    {
        v = (EditText)convertView.getTag(R.string.edittext_child);
    }
    v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 80));
    v.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.custom_edit));
    v.setEms(12);
    v.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    v.setPadding(10, 0, 5, 0);
    v.setHint(Ids[position]);
    return convertView;
}

ビューを返すときにこのエラーが発生します。

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
4

2 に答える 2

1

現在、間違ったインポートである LinearLayout Layout Params をインポートした可能性があります。それがあなたが得ている理由です

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams は android.widget.AbsListView$LayoutParams にキャストできません

AbdList Params で埋める必要がある AbsList Layout に Linear Layout params を追加しようとしているため

この行は間違っています:

v.setLayoutParams(新しい LayoutParams(LayoutParams.MATCH_PARENT, 80));

LayoutParams を次のように変更します。

AbsListView.LayoutParams

またはインポートを変更します。

import android.widget.AbsListView;
于 2013-06-18T10:35:07.620 に答える
1

AbsListView.LayoutParams を使用する

 v.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, 80));
于 2013-06-18T10:35:33.000 に答える