public class QuestionsOptionsAdapterMultipleSelectionLV extends BaseAdapter {
Context context;
ArrayList<QuestionOptionsModel> items;
String which;
CollegepondSandbox cs;
ArrayList<String> arr;
boolean isTouch = false;
int positionselected;
QuestionsOptionsAdapterMultipleSelectionLV adapter1;
public QuestionsOptionsAdapterMultipleSelectionLV(Context context,
ArrayList<QuestionOptionsModel> items) {
this.context = context;
this.items = items;
this.which = which;
this.arr = arr;
cs = new CollegepondSandbox();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return items.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return items.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
// positionselected =items.indexOf(items.get(position));
return items.indexOf(items.get(position));
}
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup
parent) {
if(convertView==null){
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.custom_options_multiple,
null);
WebView tvOptiontext;
ImageView ivOption;
LinearLayout llOptionsMultiple;
ivOption = (ImageView) convertView.findViewById(R.id.cbOption);
tvOptiontext = (WebView) convertView.findViewById(R.id.tvOptiontext);
llOptionsMultiple = (LinearLayout) convertView.findViewById(R.id.llOptionsMultiple);
tvOptiontext.loadData(items.get(position).QOption, "text/html", "utf-8");
return convertView;
}
}
我不知道为什么在打开文件后测试的数组值之后会打印这些零。我想打印数组本身而不是其他数字。我试过搞乱MAX变量,但我不知道该怎么做。
答案 0 :(得分:1)
main()中的for循环遍历数组的长度,即100个元素。您未覆盖的元素默认为0.
要解决此问题,请将数组作为参数传递给inputData(),并让它返回它放入数组的元素数量:
public static int inputData(int[] input) {
// ...
input[count] = whatever;
// ...
return count;
}
答案 1 :(得分:0)
int
到Integer
重构数组(0 - &gt; null)在打印前添加此项,它将从Integer
(非int
)数组中删除空值。 (如果int
将有零问题)
int count = 0;
for (Integer i : array) {
if (i != null) {
count++;
}
}
Integer[] newArray = new Integer[count];
int index = 0;
for (Integer i : array) {
if (i != null) {
newArray[index++] = i;
}
}