-1

私のアプリはこのエラーを出し続けます:addView(View、LayoutParams)はAdapterViewではサポートされていません

次に、解決策を探したので、アダプターをシンプルからカスタムに変更しました。次に、カスタムアダプターを作成しましたが、このエラーが発生し続けます。理由はわかりません。どうすればこれを解決できますか?

public class Main_activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_list_view);

    ListView mListView = (ListView)findViewById(R.id.mylist);

    ArrayList<String> listIds =  new ArrayList<String>();
    listIds.add("txtname");
    listIds.add("btnnum");
    listIds.add("txtTran");
    mAdapter = new CustomAdapter(this,listIds);
    mListView.setAdapter(mAdapter);


    populateList();
}

static final ArrayList<HashMap<String,String>> list = 
    new ArrayList<HashMap<String,String>>(); 

private void populateList() {
    if(!list.isEmpty())
        list.clear();

    HashMap<String,String> temp1 = new HashMap<String,String>();
    temp1.put("txtname","test1");
    temp1.put("btnnum", "1");
    temp1.put("txtTran", "4x");

    list.add(temp1);
    HashMap<String,String> temp2 = new HashMap<String,String>();
    temp2.put("txtname","test2");
    temp2.put("btnnum", "2");
    temp2.put("txtTran", "3.5x");

    list.add(temp2);
    HashMap<String,String> temp3 = new HashMap<String,String>();
    temp3.put("txtname","test3");
    temp3.put("btnnum", "3");
    temp3.put("txtTran", "3.2x");

    list.add(temp3);
    HashMap<String,String> temp4 = new HashMap<String,String>();
    temp4.put("txtname","test4");
    temp4.put("btnnum", "4");
    temp4.put("txtTran", "2.4x");

    list.add(temp4);

}
protected CustomAdapter mAdapter;
private class CustomAdapter extends ArrayAdapter<String> {

    protected Context mContext;
    protected ArrayList<String> mItems;
    protected LayoutInflater mInflater;
    public CustomAdapter(Context context, ArrayList<String> items) {
        super(context, R.layout.custom_row_view, items); // Use a custom layout file
        mContext = context;
        mItems = items;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        System.out.println("enters");
        if(convertView == null){

            convertView = mInflater.inflate(R.layout.custom_row_view,null);
        }



      ((TextView) convertView.findViewById(R.id.nametxt)).setText(list.get(position).get("txtname"));
      ((Button) convertView.findViewById(R.id.btnnum)).setText(list.get(position).get("btnnum"));
      ((TextView) convertView.findViewById(R.id.transtxt)).setText(list.get(position).get("txtTran"));

        return convertView;
    }
}

}

4

1 に答える 1

0

わかりました、それで私はこれを解決しました。問題は、レイアウトにフレームレイアウトを追加し、その詳細を入力するのを忘れたためです。次のようになりました。

 <FramLayout android:id="@+id/f1">

レイアウトが問題を引き起こしていて、それは活動によるものだと思いました。

于 2013-01-22T17:44:51.763 に答える