gpt4 book ai didi

android - android不断给我的应用这个错误:addView(View, LayoutParams) is not supported

转载 作者:行者123 更新时间:2023-12-02 11:11:03 25 4
gpt4 key购买 nike

我的应用程序不断出现此错误:AdapterView不支持addView(View,LayoutParams)

然后我将适配器从简单更改为自定义,因为我在寻找解决方案。
然后我做了我的自定义适配器,但我不断收到此错误,我不知道为什么。
我该如何解决?

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;
}
}

}

最佳答案

好的,我解决了这个问题。问题是因为我在布局中添加了framelayout,却忘了放上有关它的详细信息,例如:

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

布局给了问题,我认为这是来自 Activity 。

关于android - android不断给我的应用这个错误:addView(View, LayoutParams) is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14443313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com