gpt4 book ai didi

java - 按钮中的按钮 (android.content.Context) 无法应用于 (Java.lang.Object)

转载 作者:行者123 更新时间:2023-12-02 10:45:59 26 4
gpt4 key购买 nike

我正在尝试动态创建按钮以匹配数据表。我正在使用这个answer作为引用点,但我不断收到此错误代码: Button (android.content.Context) in Button Cannot be Applied to (Java.lang.Object)我尝试了多种方法来缓解错误代码,但我不知道如何修复它,我尝试将 map 设置为数组,但这也不起作用。代码已成功计数并显示数据,但我无法让它添加所需的按钮。

 Backendless.Data.of( "Store" ).find( queryBuilder, new AsyncCallback<List<Map>>()
{
@Override
public void handleResponse( List<Map> response )
{

int numBrands = response.size();

Button brandButtons[] = new Button[numBrands];

System.out.println("The Count of Buttons:" + numBrands);

ArrayList<Brands> productList = new ArrayList<>();



Object[] arrayList = {response};
for(int i = 0; i < brandButtons.length; i++)
{

Button brans = new Button(productList[i]);

brans.setOnClickListener();
add(brans);
brandButtons[i] = brans;




//Object element = thisIsAStringArray[i];
System.out.println( "List of Brands" + response );




}

}

最佳答案

您的错误在这一行:

Button brans = new Button(productList[i]); // here

Button类需要 Context 传递给它的构造函数调用,而您正在传递 Object 类型。

像这样使用,

Button brans = new Button(context); // here context can be activity or fragment.

//now use this brans object to set property to your programmatically created Button,
//don't forget to add it to your parent view afterwards

关于java - 按钮中的按钮 (android.content.Context) 无法应用于 (Java.lang.Object),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52571959/

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