我有這樣一個類:如何在一個方法內修改數組?
import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class workingOneWayAdapter extends BaseAdapter {
private Context mContext;
public workingOneWayAdapter(Context c) {
mContext = c;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
TextView workingLabel;
if (convertView == null) {
workingLabel = new TextView(mContext);
workingLabel.setLayoutParams(new MyGridView.LayoutParams(85, 85));
workingLabel.setPadding(10, 5, 5, 5);
workingLabel.setTextColor(Color.parseColor("#000000"));
workingLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19);
workingLabel.setSingleLine();
setTimes();
} else {
workingLabel = (TextView) convertView;
}
workingLabel.setText(workingOneWayArray[position]);
return workingLabel;
}
String[] workingOneWayArray;
void setTimes() {
workingOneWayArray = new String[] { "00:00" };
}
public int getCount() {
return workingOneWayArray.length;
}
}
但它使我的應用程序崩潰。我需要在該方法內編輯數組,因爲該數組可以從該類的其他部分訪問。你能告訴我什麼是錯的嗎?謝謝!
你能否提供這個類的更多代碼,因爲沒有什麼不對,也嘗試調試你的android應用程序 –
該應用程序在getCount()方法崩潰,但我不知道爲什麼 – BigK
也許你沒有打電話給你setTimes方法在發出你的getCount之前。向我們展示您的完整代碼 – Constantin