gpt4 book ai didi

java - 在不同的类中使用数组

转载 作者:行者123 更新时间:2023-12-01 14:10:04 25 4
gpt4 key购买 nike

我想使用从一个类到另一个类的值数组。在 ActivityReceiver 中,我获取了一个数组并将其传递给 String inkLevel [][]。

之后我想要获取特定值,以便我有 getInkLevel 并将其返回到保存我想要的特定值(即 color[])的数组中。

 public class ActivityReceiver extends Activity {

public ArrayList<String[]> arrays ;
public String[]color = new String [4];
public String[][] inkLev ;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();

if (bundle != null)
{

int count = bundle.getInt("com.PrinterStatus.AppLab.ARRAYS_COUNT", 0);
ArrayList<String[]> arrays = new ArrayList<String[]>(count);
for (int i = 0; i < count; i++)
{

arrays.add(bundle.getStringArray("com.PrinterStatus.AppLab.ARRAY_INDEX" + i));
String[][] inkLev = arrays.toArray(new String[][]{});
}
}

}
public String[] getInkLevel(String[] lev)
{
color[0]= inkLev[0][2];
color[1]= inkLev[1][2];
color[2]= inkLev[2][2];
color[3]= inkLev[3][2];

return color;

}

在另一个类(class)。我已经输入了numberC 变量。我想将特定值(例如 color[1])放入该变量中。

   ...
tonerAmountC = (TextView)mSmartView.findViewById(R.id.ImageC);
tonerAmountC.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v)
{
enterednumberC = ??;
Log.d(SampleExtensionService.LOG_TAG, "Read from file: " + enterednumberC);
tonerAmountC.setText(enterednumberC);
}
});
mSmartView.addViewToWatch(tonerAmountC);
...

你知道我应该添加什么吗?谢谢

最佳答案

您需要先使用检索数组。您需要类的实例来访问数组

someStringArray = new ActivityReceiver().getInkLever();
enteredNumberC = someStringArray[1];

关于java - 在不同的类中使用数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18589389/

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