log:
08-27 11:32:36.240: E/AndroidRuntime(7670): FATAL EXCEPTION: main
08-27 11:32:36.240: E/AndroidRuntime(7670): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
08-27 11:32:36.240: E/AndroidRuntime(7670): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
08-27 11:32:36.240: E/AndroidRuntime(7670): at java.util.ArrayList.get(ArrayList.java:304)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.widget.ListView.dispatchDraw(ListView.java:3221)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13856)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.widget.AbsListView.draw(AbsListView.java:3910)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12791)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13569)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.drawChild(ViewGroup.java:3072)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2936)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12789)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13569)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.drawChild(ViewGroup.java:3072)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2936)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12789)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13569)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.drawChild(ViewGroup.java:3072)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2936)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12789)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13569)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.drawChild(ViewGroup.java:3072)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2936)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12789)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13569)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.drawChild(ViewGroup.java:3072)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2936)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13856)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12791)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13569)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.drawChild(ViewGroup.java:3072)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2936)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12789)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13569)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.drawChild(ViewGroup.java:3072)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2936)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12789)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13569)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.drawChild(ViewGroup.java:3072)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2936)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.draw(View.java:13856)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.widget.FrameLayout.draw(FrameLayout.java:467)
08-27 11:32:36.240: E/AndroidRuntime(7670): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2226)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12791)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.View.getDisplayList(View.java:12835)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1249)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2480)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2340)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2142)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4879)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.Choreographer.doCallbacks(Choreographer.java:579)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.Choreographer.doFrame(Choreographer.java:548)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.os.Handler.handleCallback(Handler.java:725)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.os.Handler.dispatchMessage(Handler.java:92)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.os.Looper.loop(Looper.java:153)
08-27 11:32:36.240: E/AndroidRuntime(7670): at android.app.ActivityThread.main(ActivityThread.java:5293)
08-27 11:32:36.240: E/AndroidRuntime(7670): at java.lang.reflect.Method.invokeNative(Native Method)
08-27 11:32:36.240: E/AndroidRuntime(7670): at java.lang.reflect.Method.invoke(Method.java:511)
12 个解决方案
#1
很明显索引越界了啊。数组大小为0,你却取了第一行(0).
#2
数组越界。。。。
#3
请问一下, 我应该怎么处理。谢谢
#4
看一下源代码,看看数组为什么大小为0.
#5
这种问题如果要让别人更好的给你解决,就把关键代码发出来咯,比如用到的那个数组的代码
#6
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch(msg.what){
case 3:
listview.requestLayout();
listview.setAdapter(adapterRecords);
if(btLoading!=null){
btLoading.cancel();
}
break;
case 4:
// loadingData();
break;
case 7:
dilock = true;
break;
case 6:
hilock = true;
break;
}
}
};
public RecordFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_record, container,
false);
this.inflater = inflater;
EventBus.getDefault().registerSticky(this, "taskupload",addrecordBus.class);
sp = getActivity().getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE);
rbDistribute = (RadioButton) rootView.findViewById(R.id.rbdistribution);
rbHistory = (RadioButton) rootView.findViewById(R.id.rbhistory);
ivDeleteText = (ImageView) rootView.findViewById(R.id.ivDeleteText);
etSearch = (EditText) rootView.findViewById(R.id.etSearch);
Button btnSearch = (Button) rootView.findViewById(R.id.btnSearch);
btnSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!"".equals(etSearch.getText().toString())){
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
records = SearchLines.getRecordsBySearch(etSearch.getText().toString());
array.clear();
if(records!=null && records.size()>0){
for(Object o : records){
array.add(o.toString());
}
}
handler.sendEmptyMessage(4);
// new Dao(getActivity()).deleteSearch();
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
rbDistribute.setChecked(true);
dataType = "down";
} else {
Toast.makeText(getActivity(), "請輸入搜索內容!", Toast.LENGTH_SHORT).show();
}
}
});
ivDeleteText.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
etSearch.setText("");
}
});
etSearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
if (s.length() == 0) {
ivDeleteText.setVisibility(View.GONE);
} else {
ivDeleteText.setVisibility(View.VISIBLE);
}
}
});
spScreen = (Spinner) rootView.findViewById(R.id.spscreen);
String[] mItems = getResources().getStringArray(R.array.screen);
if(rbDistribute.isChecked())
handler1.sendEmptyMessage(3);
else
handler1.sendEmptyMessage(4);
rbDistribute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(dilock)
{
dilock = false;
if(dtimer!=null){
dtimer.cancel();
dtimer = new Timer();
}
handler1.sendEmptyMessage(3);
if(/*(ma.getAccess()) &&*/ (!(sp.getString("ID","").equals("serverdown"))))
{
dataType = "down";
refresh(1);
}
}
else
{
dataType = "down";
new Thread() {
public void run() {
dtimer.schedule(new MyLeaveRecordsListTask(), 0);
}
}.start();
}
}
});
rbHistory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(hilock = true)
{
hilock = false;
// if(ptimer!=null){
// ptimer.cancel();
// ptimer = new Timer();
// }
handler1.sendEmptyMessage(4);
dataType = "upload";
new Thread() {
public void run() {
ptimer.schedule(new MyLeaveRecordsListTask(), 0);
}
}.start();
}
}
});
// rbHistory.callOnClick();
addRecord = (ImageButton) rootView.findViewById(R.id.addrecord);
addRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(),
AddRecord.class);
intent.putExtra("record_type", "add");
startActivityForResult(intent, OTHER);
}
});
listview = (MyListView) rootView.findViewById(R.id.lv);
//listview.setEmptyView(rootView.findViewById(R.id.tvnorecord));
listview.setonRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
// ma.setUpdate(true);
// lv.refreshDrawableState();
// Modify by yx @20140719
// handler.sendEmptyMessage(4);
// Modify by yx @20140720
// 修改,当选择 已经提交 ,后,只重新加载本地数据库,不从 WebService 拿上传的记录数据,也没这样的接口同步上传的记录数据
// 这样修改 增加刷新速度,减少与 WebService 通讯次数
if ("upload".equals(dataType)) {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
} else {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(1).execute();
}
if(rbDistribute.isChecked())
refresh(1);
return null;
}
@Override
protected void onPostExecute(Void result) {
listview.onRefreshComplete();
}
}.execute(null, null, null);
}
});
inflater = getActivity().getLayoutInflater();
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(), 1000);
}
}.start();
// new Thread() {
// public void run() {
// utime.schedule(new detectUp(), 1000,4000);
// }
// }.start();
//
return rootView;
}
public void taskupload(addrecordBus event)
{
//上传后自动刷新
// if(event.getT())
// afterUpload();
}
public void afterUpload()
{
rbHistory.setChecked(true);
rbHistory.callOnClick();
}
@Override
public void onDestroyView() {
if(timer!=null){
timer.cancel();
}
if(ptimer != null)
ptimer.cancel();
if(dtimer != null)
dtimer.cancel();
// btLoading.cancel();
super.onDestroyView();
}
private class MyLeaveRecordsListTask extends TimerTask {
int type=0;
public MyLeaveRecordsListTask(){}
public MyLeaveRecordsListTask(int type){
this.type = type;
}
@Override
public void run() {
handler.sendEmptyMessage(4);
new testReqSearch(type).execute();
}
}
public void loadingData(){
btLoading = new Dialog(getActivity(), R.style.DialogStyle);
btLoading.requestWindowFeature(Window.FEATURE_NO_TITLE);
btLoading.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
btLoading.setContentView(R.layout.data_loading);
btLoading.setCanceledOnTouchOutside(false);
btLoading.show();
}
public void refresh(int typ)
{
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
{
switch(typ)
{
case 1:
//down
dataType = "down";
break;
default:
// dataType="upload";
break;
}
if(canFresh)
{
//SearchLines.getAssignByUser(sp.getString("ID", ""));
new testReqDown(1).execute();
canFresh = false;
}
new Thread() {
public void run() {
try {
Thread.sleep(3000);
canFresh = true;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
else
new testReqSearch().execute();
}
public void handleMessage(Message msg) {
switch(msg.what){
case 3:
listview.requestLayout();
listview.setAdapter(adapterRecords);
if(btLoading!=null){
btLoading.cancel();
}
break;
case 4:
// loadingData();
break;
case 7:
dilock = true;
break;
case 6:
hilock = true;
break;
}
}
};
public RecordFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_record, container,
false);
this.inflater = inflater;
EventBus.getDefault().registerSticky(this, "taskupload",addrecordBus.class);
sp = getActivity().getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE);
rbDistribute = (RadioButton) rootView.findViewById(R.id.rbdistribution);
rbHistory = (RadioButton) rootView.findViewById(R.id.rbhistory);
ivDeleteText = (ImageView) rootView.findViewById(R.id.ivDeleteText);
etSearch = (EditText) rootView.findViewById(R.id.etSearch);
Button btnSearch = (Button) rootView.findViewById(R.id.btnSearch);
btnSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!"".equals(etSearch.getText().toString())){
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
records = SearchLines.getRecordsBySearch(etSearch.getText().toString());
array.clear();
if(records!=null && records.size()>0){
for(Object o : records){
array.add(o.toString());
}
}
handler.sendEmptyMessage(4);
// new Dao(getActivity()).deleteSearch();
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
rbDistribute.setChecked(true);
dataType = "down";
} else {
Toast.makeText(getActivity(), "請輸入搜索內容!", Toast.LENGTH_SHORT).show();
}
}
});
ivDeleteText.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
etSearch.setText("");
}
});
etSearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
if (s.length() == 0) {
ivDeleteText.setVisibility(View.GONE);
} else {
ivDeleteText.setVisibility(View.VISIBLE);
}
}
});
spScreen = (Spinner) rootView.findViewById(R.id.spscreen);
String[] mItems = getResources().getStringArray(R.array.screen);
if(rbDistribute.isChecked())
handler1.sendEmptyMessage(3);
else
handler1.sendEmptyMessage(4);
rbDistribute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(dilock)
{
dilock = false;
if(dtimer!=null){
dtimer.cancel();
dtimer = new Timer();
}
handler1.sendEmptyMessage(3);
if(/*(ma.getAccess()) &&*/ (!(sp.getString("ID","").equals("serverdown"))))
{
dataType = "down";
refresh(1);
}
}
else
{
dataType = "down";
new Thread() {
public void run() {
dtimer.schedule(new MyLeaveRecordsListTask(), 0);
}
}.start();
}
}
});
rbHistory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(hilock = true)
{
hilock = false;
// if(ptimer!=null){
// ptimer.cancel();
// ptimer = new Timer();
// }
handler1.sendEmptyMessage(4);
dataType = "upload";
new Thread() {
public void run() {
ptimer.schedule(new MyLeaveRecordsListTask(), 0);
}
}.start();
}
}
});
// rbHistory.callOnClick();
addRecord = (ImageButton) rootView.findViewById(R.id.addrecord);
addRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(),
AddRecord.class);
intent.putExtra("record_type", "add");
startActivityForResult(intent, OTHER);
}
});
listview = (MyListView) rootView.findViewById(R.id.lv);
//listview.setEmptyView(rootView.findViewById(R.id.tvnorecord));
listview.setonRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
// ma.setUpdate(true);
// lv.refreshDrawableState();
// Modify by yx @20140719
// handler.sendEmptyMessage(4);
// Modify by yx @20140720
// 修改,当选择 已经提交 ,后,只重新加载本地数据库,不从 WebService 拿上传的记录数据,也没这样的接口同步上传的记录数据
// 这样修改 增加刷新速度,减少与 WebService 通讯次数
if ("upload".equals(dataType)) {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
} else {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(1).execute();
}
if(rbDistribute.isChecked())
refresh(1);
return null;
}
@Override
protected void onPostExecute(Void result) {
listview.onRefreshComplete();
}
}.execute(null, null, null);
}
});
inflater = getActivity().getLayoutInflater();
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(), 1000);
}
}.start();
// new Thread() {
// public void run() {
// utime.schedule(new detectUp(), 1000,4000);
// }
// }.start();
//
return rootView;
}
public void taskupload(addrecordBus event)
{
//上传后自动刷新
// if(event.getT())
// afterUpload();
}
public void afterUpload()
{
rbHistory.setChecked(true);
rbHistory.callOnClick();
}
@Override
public void onDestroyView() {
if(timer!=null){
timer.cancel();
}
if(ptimer != null)
ptimer.cancel();
if(dtimer != null)
dtimer.cancel();
// btLoading.cancel();
super.onDestroyView();
}
private class MyLeaveRecordsListTask extends TimerTask {
int type=0;
public MyLeaveRecordsListTask(){}
public MyLeaveRecordsListTask(int type){
this.type = type;
}
@Override
public void run() {
handler.sendEmptyMessage(4);
new testReqSearch(type).execute();
}
}
public void loadingData(){
btLoading = new Dialog(getActivity(), R.style.DialogStyle);
btLoading.requestWindowFeature(Window.FEATURE_NO_TITLE);
btLoading.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
btLoading.setContentView(R.layout.data_loading);
btLoading.setCanceledOnTouchOutside(false);
btLoading.show();
}
public void refresh(int typ)
{
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
{
switch(typ)
{
case 1:
//down
dataType = "down";
break;
default:
// dataType="upload";
break;
}
if(canFresh)
{
//SearchLines.getAssignByUser(sp.getString("ID", ""));
new testReqDown(1).execute();
canFresh = false;
}
new Thread() {
public void run() {
try {
Thread.sleep(3000);
canFresh = true;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
else
new testReqSearch().execute();
}
#7
public class Adapter extends BaseAdapter {
LayoutInflater inflater;
List<String> array;
private ImageButton curDel_btn;
private TextView mtv2;
private float x, ux;
public Adapter(LayoutInflater inf, List<String> arry) {
this.inflater = inf;
this.array = arry;
}
@Override
public int getCount() {
return array.size();
}
@Override
public Object getItem(int position) {
return array.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = inflater.inflate(R.layout.adapter_listview,parent,false);
vh.tv1 = (TextView) convertView.findViewById(R.id.textView1);
vh.tv1.setTextColor(Color.BLACK);
vh.tv2 = (TextView) convertView.findViewById(R.id.textView2);
vh.tv2.setTextColor(Color.BLACK);
vh.tv4 = (TextView) convertView.findViewById(R.id.textView3);
vh.tv4.setTextColor(Color.BLACK);
vh.tv3 = (TextView) convertView.findViewById(R.id.textView4);
vh.tv3.setTextColor(Color.BLACK);
//vh.del = (ImageButton) convertView.findViewById(R.id.del);
convertView.setTag(vh);
}
vh = (ViewHolder) convertView.getTag();
convertView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
final ViewHolder holder = (ViewHolder) v.getTag();
// 当按下时处理
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// 设置背景为选中状态
//v.setBackgroundResource(R.drawable.mm_listitem_pressed);
// 获取按下时的x轴坐标
//x = event.getX();
// 判断之前是否出现了删除按钮如果存在就隐藏
if (curDel_btn != null) {
//curDel_btn.setVisibility(View.GONE);
//mtv2.setVisibility(View.VISIBLE);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {// 松开处理
// 设置背景为未选中正常状态
//v.setBackgroundResource(R.drawable.mm_listitem_normal);
// 获取松开时的x坐标
//ux = event.getX();
// 判断当前项中按钮控件不为空时
if (holder.del != null) {
// 按下和松开绝对值差当大于20时显示删除按钮,否则不显示
if (Math.abs(x - ux) > 10) {
//holder.del.setVisibility(View.VISIBLE);
//holder.tv2.setVisibility(View.GONE);
//curDel_btn = holder.del;
//mtv2 = holder.tv2;
} else {
if(array.size()>0)
{
Intent intent = new Intent(
getActivity(),
AddRecord.class);
intent.putExtra("ids", array.get(position));
intent.putExtra("ind", position);
Toast.makeText(getActivity(), ""+position,Toast.LENGTH_LONG).show();
Log.d("Array", array.get(position));
Log.d("Position", ""+position);
intent.putExtra("record_type", "update");
//startActivityForResult(intent, OTHER);
//getActivity().overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
//getActivity().overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
//getActivity().finish();
}
}
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {// 当滑动时背景为选中状态
//v.setBackgroundResource(R.drawable.mm_listitem_pressed);
} else {// 其他模式
// 设置背景为未选中正常状态
//v.setBackgroundResource(R.drawable.mm_listitem_normal);
}
return true;
}
});
// //vh.del.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// if (curDel_btn != null)
// curDel_btn.setVisibility(View.GONE);
//// Dao dao = new Dao(getActivity());
// //LocationService ls = new LocationService();
// //ls.getNewdb();
//// if(dao.deleteId(CPCUtil.getPositionObj(array.get(position))[19]) == 1){
//// new testReqSearch().execute();
//// }
// }
// });
if(array.size() >= position)
{
// vh.tv1.setText("test");
// vh.tv2.setText("test");
// vh.tv3.setText("test");
// vh.tv4.setText("test");
if(CPCUtil.getStatu(array.get(position)).equals("2"))
{
// vh.tv1.setTextColor(Color.RED);
// vh.tv2.setTextColor(Color.RED);
vh.tv3.setTextColor(Color.RED);
// vh.tv4.setTextColor(Color.RED);
vh.tv1.setText(CPCUtil.getSeq(array.get(position))+") ");
vh.tv4.setText(" "+ CPCUtil.getPositionObj(array.get(position))[18]);
vh.tv2.setText(CPCUtil.getTime(array.get(position)));
if(array.size() > 0)
vh.tv3.setText("1".equals(CPCUtil.getStatu(array.get(position)))?"已上傳":"2".equals(CPCUtil.getStatu(array.get(position)))?"已下載":"3".equals(CPCUtil.getStatu(array.get(position)))?"已完成":"上傳中");
}
else
{
vh.tv1.setText(CPCUtil.getSeq(array.get(position))+") ");
vh.tv4.setText(" "+CPCUtil.getPositionObj(array.get(position))[18]);
vh.tv2.setText(CPCUtil.getTime(array.get(position)));
if(array.size() > 0)
vh.tv3.setText("1".equals(CPCUtil.getStatu(array.get(position)))?"已上傳":"2".equals(CPCUtil.getStatu(array.get(position)))?"已下載":"3".equals(CPCUtil.getStatu(array.get(position)))?"已完成":"上傳中");
}
}
return convertView;
}
class ViewHolder {
TextView tv1, tv2, tv3,tv4;
ImageButton del;
}
}
public void diSpan()
{
String[] mItems = {" 全部"," 已完成"," 已下載"};
ArrayAdapter<String> _Adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, mItems);
_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spScreen.setAdapter(_Adapter);
spScreen.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
//默认排序
case 0:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(0), 0);
}
}.start();
break;
//已完成
case 1:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(1), 0);
}
}.start();
break;
//上传中
case 2:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(4), 0);
}
}.start();
break;
}}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
public void hiSpan()
{
String[] mItems = {" 全部"," 上傳中"," 已上傳"};
ArrayAdapter<String> _Adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, mItems);
_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spScreen.setAdapter(_Adapter);
spScreen.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
//默认排序
case 0:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(0), 0);
}
}.start();
break;
//已完成
case 1:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(2), 0);
}
}.start();
break;
//上传中
case 2:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(3), 0);
}
}.start();
break;
}}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
LayoutInflater inflater;
List<String> array;
private ImageButton curDel_btn;
private TextView mtv2;
private float x, ux;
public Adapter(LayoutInflater inf, List<String> arry) {
this.inflater = inf;
this.array = arry;
}
@Override
public int getCount() {
return array.size();
}
@Override
public Object getItem(int position) {
return array.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = inflater.inflate(R.layout.adapter_listview,parent,false);
vh.tv1 = (TextView) convertView.findViewById(R.id.textView1);
vh.tv1.setTextColor(Color.BLACK);
vh.tv2 = (TextView) convertView.findViewById(R.id.textView2);
vh.tv2.setTextColor(Color.BLACK);
vh.tv4 = (TextView) convertView.findViewById(R.id.textView3);
vh.tv4.setTextColor(Color.BLACK);
vh.tv3 = (TextView) convertView.findViewById(R.id.textView4);
vh.tv3.setTextColor(Color.BLACK);
//vh.del = (ImageButton) convertView.findViewById(R.id.del);
convertView.setTag(vh);
}
vh = (ViewHolder) convertView.getTag();
convertView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
final ViewHolder holder = (ViewHolder) v.getTag();
// 当按下时处理
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// 设置背景为选中状态
//v.setBackgroundResource(R.drawable.mm_listitem_pressed);
// 获取按下时的x轴坐标
//x = event.getX();
// 判断之前是否出现了删除按钮如果存在就隐藏
if (curDel_btn != null) {
//curDel_btn.setVisibility(View.GONE);
//mtv2.setVisibility(View.VISIBLE);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {// 松开处理
// 设置背景为未选中正常状态
//v.setBackgroundResource(R.drawable.mm_listitem_normal);
// 获取松开时的x坐标
//ux = event.getX();
// 判断当前项中按钮控件不为空时
if (holder.del != null) {
// 按下和松开绝对值差当大于20时显示删除按钮,否则不显示
if (Math.abs(x - ux) > 10) {
//holder.del.setVisibility(View.VISIBLE);
//holder.tv2.setVisibility(View.GONE);
//curDel_btn = holder.del;
//mtv2 = holder.tv2;
} else {
if(array.size()>0)
{
Intent intent = new Intent(
getActivity(),
AddRecord.class);
intent.putExtra("ids", array.get(position));
intent.putExtra("ind", position);
Toast.makeText(getActivity(), ""+position,Toast.LENGTH_LONG).show();
Log.d("Array", array.get(position));
Log.d("Position", ""+position);
intent.putExtra("record_type", "update");
//startActivityForResult(intent, OTHER);
//getActivity().overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
//getActivity().overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
//getActivity().finish();
}
}
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {// 当滑动时背景为选中状态
//v.setBackgroundResource(R.drawable.mm_listitem_pressed);
} else {// 其他模式
// 设置背景为未选中正常状态
//v.setBackgroundResource(R.drawable.mm_listitem_normal);
}
return true;
}
});
// //vh.del.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// if (curDel_btn != null)
// curDel_btn.setVisibility(View.GONE);
//// Dao dao = new Dao(getActivity());
// //LocationService ls = new LocationService();
// //ls.getNewdb();
//// if(dao.deleteId(CPCUtil.getPositionObj(array.get(position))[19]) == 1){
//// new testReqSearch().execute();
//// }
// }
// });
if(array.size() >= position)
{
// vh.tv1.setText("test");
// vh.tv2.setText("test");
// vh.tv3.setText("test");
// vh.tv4.setText("test");
if(CPCUtil.getStatu(array.get(position)).equals("2"))
{
// vh.tv1.setTextColor(Color.RED);
// vh.tv2.setTextColor(Color.RED);
vh.tv3.setTextColor(Color.RED);
// vh.tv4.setTextColor(Color.RED);
vh.tv1.setText(CPCUtil.getSeq(array.get(position))+") ");
vh.tv4.setText(" "+ CPCUtil.getPositionObj(array.get(position))[18]);
vh.tv2.setText(CPCUtil.getTime(array.get(position)));
if(array.size() > 0)
vh.tv3.setText("1".equals(CPCUtil.getStatu(array.get(position)))?"已上傳":"2".equals(CPCUtil.getStatu(array.get(position)))?"已下載":"3".equals(CPCUtil.getStatu(array.get(position)))?"已完成":"上傳中");
}
else
{
vh.tv1.setText(CPCUtil.getSeq(array.get(position))+") ");
vh.tv4.setText(" "+CPCUtil.getPositionObj(array.get(position))[18]);
vh.tv2.setText(CPCUtil.getTime(array.get(position)));
if(array.size() > 0)
vh.tv3.setText("1".equals(CPCUtil.getStatu(array.get(position)))?"已上傳":"2".equals(CPCUtil.getStatu(array.get(position)))?"已下載":"3".equals(CPCUtil.getStatu(array.get(position)))?"已完成":"上傳中");
}
}
return convertView;
}
class ViewHolder {
TextView tv1, tv2, tv3,tv4;
ImageButton del;
}
}
public void diSpan()
{
String[] mItems = {" 全部"," 已完成"," 已下載"};
ArrayAdapter<String> _Adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, mItems);
_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spScreen.setAdapter(_Adapter);
spScreen.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
//默认排序
case 0:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(0), 0);
}
}.start();
break;
//已完成
case 1:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(1), 0);
}
}.start();
break;
//上传中
case 2:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(4), 0);
}
}.start();
break;
}}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
public void hiSpan()
{
String[] mItems = {" 全部"," 上傳中"," 已上傳"};
ArrayAdapter<String> _Adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, mItems);
_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spScreen.setAdapter(_Adapter);
spScreen.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
//默认排序
case 0:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(0), 0);
}
}.start();
break;
//已完成
case 1:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(2), 0);
}
}.start();
break;
//上传中
case 2:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(3), 0);
}
}.start();
break;
}}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
#8
Handler handler1 = new Handler(){
public void handleMessage(android.os.Message msg) {
String showMessage = "";
switch (msg.what) {
case GETWSDLRESULT:
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
// showMessage = "WSDL: " + GetResult;
// Toast.makeText(getActivity(), GetResult, Toast.LENGTH_LONG).show();
// EnvironmentShare.showToast(Main.this, showMessage);
break;
case 1:
rbDistribute.callOnClick();
break;
case 2:
rbHistory.callOnClick();
break;
case 3:
diSpan();
break;
case 4:
hiSpan();
break;
default:
break;
}
// 显示提示信息并 设置标题
// EnvironmentShare.showTitle(Main.this, showMessage, true);
// GetResult = "";
};
};
/*
public interface ICallback {
void execute(Vector<Object> obj,int nType);
}
ICallback listen1 = new ICallback(){
public void execute(Vector <Object> mResult,int nType)
{
switch (nType) {
case GETWSDLRESULT:
records = mResult;
handler1.sendEmptyMessage(GETWSDLRESULT);
// Toast.makeText(getActivity(), GetResult, Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
};
*/
//*****************************************************************
class testReqSearch extends AsyncTask<Void, Void, Void> {
int type = 0;
public testReqSearch(){}
public testReqSearch(int type){
this.type = type;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... params) {
Dao dao = new Dao(getActivity());
List<TaskInfo> tasks = new ArrayList<TaskInfo>();
if("down".equals(dataType)){
tasks = dao.getAllArrayOnDown(type);
} else if("upload".equals(dataType)){
tasks = dao.getAllArrayOnUpload(type);
}
array.clear();
tem.clear();
if(tasks!=null && tasks.size()>0){
obj = new Object[tasks.size()];
for(int i=0; i<tasks.size(); i++){
StringBuilder sb = new StringBuilder();
sb.append(tasks.get(i).getTaskID()).append("^").append(tasks.get(i).getType()).append("^")
.append(tasks.get(i).getCreateDate()).append("^").append("").append("^")
.append(tasks.get(i).getRecord()).append("^").append(tasks.get(i).getPhotoUrl()).append("^")
.append(tasks.get(i).getRecordUrl()).append("^").append("").append("^")
.append(tasks.get(i).getPhotoName()).append("^").append(tasks.get(i).getRecordName()).append("^")
.append(tasks.get(i).getLongitude()).append("^").append(tasks.get(i).getLatitude()).append("^")
.append(tasks.get(i).getUserId()).append("^").append(tasks.get(i).getCity()).append("^")
.append(tasks.get(i).getArea()).append("^").append(tasks.get(i).getStreet()).append("^")
.append(tasks.get(i).getAddress()).append("^").append(tasks.get(i).getStatus()).append("^")
.append(tasks.get(i).getTaskNum()).append("^").append(tasks.get(i).getId()).append("^").append(tasks.get(i).getSeq());
obj[i] = sb.toString();
array.add(sb.toString());
sb = null;
}
if(array.size()>0)
{
for(int b = array.size() -1; b >= 0; b--)
{
tem.add(array.get(b));
}
}
}
if(tem.size() >0)
adapterRecords = new Adapter(inflater, tem);
handler.sendEmptyMessage(3);
if("down".equals(dataType))
handler.sendEmptyMessage(7);
if("upload".equals(dataType))
handler.sendEmptyMessage(6);
return null;
}
}
class testReqDown extends AsyncTask<Void, Void, Void> {
int reqType = 0;
public testReqDown(int reqType){
this.reqType = reqType;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... params) {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
{
dao = new Dao(getActivity());
if(reqType == 1){
record = SearchLines.getAssignByUser(sp.getString("ID", ""));
}
if((record != null) && (record.size()>0)){
obj = new Object[record.size()];
for(Object obj : record){
String[] objs = CPCUtil.getPositionObj(obj.toString());
Object[] datas = new Object[20];
datas[0] = null;
datas[1] = 6;
datas[2] = objs[2];
datas[3] = objs[12];
datas[4] = objs[4];
datas[5] = objs[5];
datas[6] = objs[6];
datas[7] = objs[8];
datas[8] = objs[9];
datas[9] = objs[13];
datas[10] = objs[14];
datas[11] = objs[15];
datas[12] = objs[16];
datas[13] = objs[17];
// datas[20] = null;
if(!"".equals(datas[5]) && !"".equals(datas[6])){
datas[14] = datas[5]+","+datas[6]+",";
} else if(!"".equals(EntityConfig.obj[5]) && "".equals(datas[6])){
datas[14] = datas[5];
} else if("".equals(EntityConfig.obj[5]) && !"".equals(datas[6])){
datas[14] = datas[6];
} else {
datas[14] = "";
}
datas[15] = objs[0];
datas[16] = objs[11];
datas[17] = objs[10];
datas[18] = objs[18];
if(dao.getNumber() != 0)
{
seq = dao.getNumber();
datas[19] = seq + 1;
}
else
datas[19] = 1;
if(dao != null) // Modify by yx @ 20140719 dao == null ?
dao.toRecordInsert(datas, datas[15]);
}
}
}
if(array.size()!=0)
adapterRecords = new Adapter(inflater, array);
// handler.sendEmptyMessage(3);
new testReqSearch().execute(null,null,null);
return null;
}
}
}
public void handleMessage(android.os.Message msg) {
String showMessage = "";
switch (msg.what) {
case GETWSDLRESULT:
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
// showMessage = "WSDL: " + GetResult;
// Toast.makeText(getActivity(), GetResult, Toast.LENGTH_LONG).show();
// EnvironmentShare.showToast(Main.this, showMessage);
break;
case 1:
rbDistribute.callOnClick();
break;
case 2:
rbHistory.callOnClick();
break;
case 3:
diSpan();
break;
case 4:
hiSpan();
break;
default:
break;
}
// 显示提示信息并 设置标题
// EnvironmentShare.showTitle(Main.this, showMessage, true);
// GetResult = "";
};
};
/*
public interface ICallback {
void execute(Vector<Object> obj,int nType);
}
ICallback listen1 = new ICallback(){
public void execute(Vector <Object> mResult,int nType)
{
switch (nType) {
case GETWSDLRESULT:
records = mResult;
handler1.sendEmptyMessage(GETWSDLRESULT);
// Toast.makeText(getActivity(), GetResult, Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
};
*/
//*****************************************************************
class testReqSearch extends AsyncTask<Void, Void, Void> {
int type = 0;
public testReqSearch(){}
public testReqSearch(int type){
this.type = type;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... params) {
Dao dao = new Dao(getActivity());
List<TaskInfo> tasks = new ArrayList<TaskInfo>();
if("down".equals(dataType)){
tasks = dao.getAllArrayOnDown(type);
} else if("upload".equals(dataType)){
tasks = dao.getAllArrayOnUpload(type);
}
array.clear();
tem.clear();
if(tasks!=null && tasks.size()>0){
obj = new Object[tasks.size()];
for(int i=0; i<tasks.size(); i++){
StringBuilder sb = new StringBuilder();
sb.append(tasks.get(i).getTaskID()).append("^").append(tasks.get(i).getType()).append("^")
.append(tasks.get(i).getCreateDate()).append("^").append("").append("^")
.append(tasks.get(i).getRecord()).append("^").append(tasks.get(i).getPhotoUrl()).append("^")
.append(tasks.get(i).getRecordUrl()).append("^").append("").append("^")
.append(tasks.get(i).getPhotoName()).append("^").append(tasks.get(i).getRecordName()).append("^")
.append(tasks.get(i).getLongitude()).append("^").append(tasks.get(i).getLatitude()).append("^")
.append(tasks.get(i).getUserId()).append("^").append(tasks.get(i).getCity()).append("^")
.append(tasks.get(i).getArea()).append("^").append(tasks.get(i).getStreet()).append("^")
.append(tasks.get(i).getAddress()).append("^").append(tasks.get(i).getStatus()).append("^")
.append(tasks.get(i).getTaskNum()).append("^").append(tasks.get(i).getId()).append("^").append(tasks.get(i).getSeq());
obj[i] = sb.toString();
array.add(sb.toString());
sb = null;
}
if(array.size()>0)
{
for(int b = array.size() -1; b >= 0; b--)
{
tem.add(array.get(b));
}
}
}
if(tem.size() >0)
adapterRecords = new Adapter(inflater, tem);
handler.sendEmptyMessage(3);
if("down".equals(dataType))
handler.sendEmptyMessage(7);
if("upload".equals(dataType))
handler.sendEmptyMessage(6);
return null;
}
}
class testReqDown extends AsyncTask<Void, Void, Void> {
int reqType = 0;
public testReqDown(int reqType){
this.reqType = reqType;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... params) {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
{
dao = new Dao(getActivity());
if(reqType == 1){
record = SearchLines.getAssignByUser(sp.getString("ID", ""));
}
if((record != null) && (record.size()>0)){
obj = new Object[record.size()];
for(Object obj : record){
String[] objs = CPCUtil.getPositionObj(obj.toString());
Object[] datas = new Object[20];
datas[0] = null;
datas[1] = 6;
datas[2] = objs[2];
datas[3] = objs[12];
datas[4] = objs[4];
datas[5] = objs[5];
datas[6] = objs[6];
datas[7] = objs[8];
datas[8] = objs[9];
datas[9] = objs[13];
datas[10] = objs[14];
datas[11] = objs[15];
datas[12] = objs[16];
datas[13] = objs[17];
// datas[20] = null;
if(!"".equals(datas[5]) && !"".equals(datas[6])){
datas[14] = datas[5]+","+datas[6]+",";
} else if(!"".equals(EntityConfig.obj[5]) && "".equals(datas[6])){
datas[14] = datas[5];
} else if("".equals(EntityConfig.obj[5]) && !"".equals(datas[6])){
datas[14] = datas[6];
} else {
datas[14] = "";
}
datas[15] = objs[0];
datas[16] = objs[11];
datas[17] = objs[10];
datas[18] = objs[18];
if(dao.getNumber() != 0)
{
seq = dao.getNumber();
datas[19] = seq + 1;
}
else
datas[19] = 1;
if(dao != null) // Modify by yx @ 20140719 dao == null ?
dao.toRecordInsert(datas, datas[15]);
}
}
}
if(array.size()!=0)
adapterRecords = new Adapter(inflater, array);
// handler.sendEmptyMessage(3);
new testReqSearch().execute(null,null,null);
return null;
}
}
}
#9
我在下拉刷新的时候也遇到过类似的问题
我的解决办法 刷新之前不要清空list 当数据已经返回后 清空list 然后将新数据add进list中 然后notifyDataSetChanged
不知道这个方法适用楼主不 不过试试总没坏处
我的解决办法 刷新之前不要清空list 当数据已经返回后 清空list 然后将新数据add进list中 然后notifyDataSetChanged
不知道这个方法适用楼主不 不过试试总没坏处
#10
这个方法楼主可以尝试下。
#11
遇到了同样的问题,只看到异常反馈无法定位问题,楼主能重现么?在什么情况下发生?有解决了?
#12
数组越界,最好做一个为大小为0时处理一下!
#1
很明显索引越界了啊。数组大小为0,你却取了第一行(0).
#2
数组越界。。。。
#3
请问一下, 我应该怎么处理。谢谢
#4
看一下源代码,看看数组为什么大小为0.
#5
这种问题如果要让别人更好的给你解决,就把关键代码发出来咯,比如用到的那个数组的代码
#6
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch(msg.what){
case 3:
listview.requestLayout();
listview.setAdapter(adapterRecords);
if(btLoading!=null){
btLoading.cancel();
}
break;
case 4:
// loadingData();
break;
case 7:
dilock = true;
break;
case 6:
hilock = true;
break;
}
}
};
public RecordFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_record, container,
false);
this.inflater = inflater;
EventBus.getDefault().registerSticky(this, "taskupload",addrecordBus.class);
sp = getActivity().getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE);
rbDistribute = (RadioButton) rootView.findViewById(R.id.rbdistribution);
rbHistory = (RadioButton) rootView.findViewById(R.id.rbhistory);
ivDeleteText = (ImageView) rootView.findViewById(R.id.ivDeleteText);
etSearch = (EditText) rootView.findViewById(R.id.etSearch);
Button btnSearch = (Button) rootView.findViewById(R.id.btnSearch);
btnSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!"".equals(etSearch.getText().toString())){
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
records = SearchLines.getRecordsBySearch(etSearch.getText().toString());
array.clear();
if(records!=null && records.size()>0){
for(Object o : records){
array.add(o.toString());
}
}
handler.sendEmptyMessage(4);
// new Dao(getActivity()).deleteSearch();
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
rbDistribute.setChecked(true);
dataType = "down";
} else {
Toast.makeText(getActivity(), "請輸入搜索內容!", Toast.LENGTH_SHORT).show();
}
}
});
ivDeleteText.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
etSearch.setText("");
}
});
etSearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
if (s.length() == 0) {
ivDeleteText.setVisibility(View.GONE);
} else {
ivDeleteText.setVisibility(View.VISIBLE);
}
}
});
spScreen = (Spinner) rootView.findViewById(R.id.spscreen);
String[] mItems = getResources().getStringArray(R.array.screen);
if(rbDistribute.isChecked())
handler1.sendEmptyMessage(3);
else
handler1.sendEmptyMessage(4);
rbDistribute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(dilock)
{
dilock = false;
if(dtimer!=null){
dtimer.cancel();
dtimer = new Timer();
}
handler1.sendEmptyMessage(3);
if(/*(ma.getAccess()) &&*/ (!(sp.getString("ID","").equals("serverdown"))))
{
dataType = "down";
refresh(1);
}
}
else
{
dataType = "down";
new Thread() {
public void run() {
dtimer.schedule(new MyLeaveRecordsListTask(), 0);
}
}.start();
}
}
});
rbHistory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(hilock = true)
{
hilock = false;
// if(ptimer!=null){
// ptimer.cancel();
// ptimer = new Timer();
// }
handler1.sendEmptyMessage(4);
dataType = "upload";
new Thread() {
public void run() {
ptimer.schedule(new MyLeaveRecordsListTask(), 0);
}
}.start();
}
}
});
// rbHistory.callOnClick();
addRecord = (ImageButton) rootView.findViewById(R.id.addrecord);
addRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(),
AddRecord.class);
intent.putExtra("record_type", "add");
startActivityForResult(intent, OTHER);
}
});
listview = (MyListView) rootView.findViewById(R.id.lv);
//listview.setEmptyView(rootView.findViewById(R.id.tvnorecord));
listview.setonRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
// ma.setUpdate(true);
// lv.refreshDrawableState();
// Modify by yx @20140719
// handler.sendEmptyMessage(4);
// Modify by yx @20140720
// 修改,当选择 已经提交 ,后,只重新加载本地数据库,不从 WebService 拿上传的记录数据,也没这样的接口同步上传的记录数据
// 这样修改 增加刷新速度,减少与 WebService 通讯次数
if ("upload".equals(dataType)) {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
} else {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(1).execute();
}
if(rbDistribute.isChecked())
refresh(1);
return null;
}
@Override
protected void onPostExecute(Void result) {
listview.onRefreshComplete();
}
}.execute(null, null, null);
}
});
inflater = getActivity().getLayoutInflater();
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(), 1000);
}
}.start();
// new Thread() {
// public void run() {
// utime.schedule(new detectUp(), 1000,4000);
// }
// }.start();
//
return rootView;
}
public void taskupload(addrecordBus event)
{
//上传后自动刷新
// if(event.getT())
// afterUpload();
}
public void afterUpload()
{
rbHistory.setChecked(true);
rbHistory.callOnClick();
}
@Override
public void onDestroyView() {
if(timer!=null){
timer.cancel();
}
if(ptimer != null)
ptimer.cancel();
if(dtimer != null)
dtimer.cancel();
// btLoading.cancel();
super.onDestroyView();
}
private class MyLeaveRecordsListTask extends TimerTask {
int type=0;
public MyLeaveRecordsListTask(){}
public MyLeaveRecordsListTask(int type){
this.type = type;
}
@Override
public void run() {
handler.sendEmptyMessage(4);
new testReqSearch(type).execute();
}
}
public void loadingData(){
btLoading = new Dialog(getActivity(), R.style.DialogStyle);
btLoading.requestWindowFeature(Window.FEATURE_NO_TITLE);
btLoading.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
btLoading.setContentView(R.layout.data_loading);
btLoading.setCanceledOnTouchOutside(false);
btLoading.show();
}
public void refresh(int typ)
{
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
{
switch(typ)
{
case 1:
//down
dataType = "down";
break;
default:
// dataType="upload";
break;
}
if(canFresh)
{
//SearchLines.getAssignByUser(sp.getString("ID", ""));
new testReqDown(1).execute();
canFresh = false;
}
new Thread() {
public void run() {
try {
Thread.sleep(3000);
canFresh = true;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
else
new testReqSearch().execute();
}
public void handleMessage(Message msg) {
switch(msg.what){
case 3:
listview.requestLayout();
listview.setAdapter(adapterRecords);
if(btLoading!=null){
btLoading.cancel();
}
break;
case 4:
// loadingData();
break;
case 7:
dilock = true;
break;
case 6:
hilock = true;
break;
}
}
};
public RecordFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_record, container,
false);
this.inflater = inflater;
EventBus.getDefault().registerSticky(this, "taskupload",addrecordBus.class);
sp = getActivity().getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE);
rbDistribute = (RadioButton) rootView.findViewById(R.id.rbdistribution);
rbHistory = (RadioButton) rootView.findViewById(R.id.rbhistory);
ivDeleteText = (ImageView) rootView.findViewById(R.id.ivDeleteText);
etSearch = (EditText) rootView.findViewById(R.id.etSearch);
Button btnSearch = (Button) rootView.findViewById(R.id.btnSearch);
btnSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!"".equals(etSearch.getText().toString())){
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
records = SearchLines.getRecordsBySearch(etSearch.getText().toString());
array.clear();
if(records!=null && records.size()>0){
for(Object o : records){
array.add(o.toString());
}
}
handler.sendEmptyMessage(4);
// new Dao(getActivity()).deleteSearch();
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
rbDistribute.setChecked(true);
dataType = "down";
} else {
Toast.makeText(getActivity(), "請輸入搜索內容!", Toast.LENGTH_SHORT).show();
}
}
});
ivDeleteText.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
etSearch.setText("");
}
});
etSearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
if (s.length() == 0) {
ivDeleteText.setVisibility(View.GONE);
} else {
ivDeleteText.setVisibility(View.VISIBLE);
}
}
});
spScreen = (Spinner) rootView.findViewById(R.id.spscreen);
String[] mItems = getResources().getStringArray(R.array.screen);
if(rbDistribute.isChecked())
handler1.sendEmptyMessage(3);
else
handler1.sendEmptyMessage(4);
rbDistribute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(dilock)
{
dilock = false;
if(dtimer!=null){
dtimer.cancel();
dtimer = new Timer();
}
handler1.sendEmptyMessage(3);
if(/*(ma.getAccess()) &&*/ (!(sp.getString("ID","").equals("serverdown"))))
{
dataType = "down";
refresh(1);
}
}
else
{
dataType = "down";
new Thread() {
public void run() {
dtimer.schedule(new MyLeaveRecordsListTask(), 0);
}
}.start();
}
}
});
rbHistory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(hilock = true)
{
hilock = false;
// if(ptimer!=null){
// ptimer.cancel();
// ptimer = new Timer();
// }
handler1.sendEmptyMessage(4);
dataType = "upload";
new Thread() {
public void run() {
ptimer.schedule(new MyLeaveRecordsListTask(), 0);
}
}.start();
}
}
});
// rbHistory.callOnClick();
addRecord = (ImageButton) rootView.findViewById(R.id.addrecord);
addRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(),
AddRecord.class);
intent.putExtra("record_type", "add");
startActivityForResult(intent, OTHER);
}
});
listview = (MyListView) rootView.findViewById(R.id.lv);
//listview.setEmptyView(rootView.findViewById(R.id.tvnorecord));
listview.setonRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
// ma.setUpdate(true);
// lv.refreshDrawableState();
// Modify by yx @20140719
// handler.sendEmptyMessage(4);
// Modify by yx @20140720
// 修改,当选择 已经提交 ,后,只重新加载本地数据库,不从 WebService 拿上传的记录数据,也没这样的接口同步上传的记录数据
// 这样修改 增加刷新速度,减少与 WebService 通讯次数
if ("upload".equals(dataType)) {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
} else {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(1).execute();
}
if(rbDistribute.isChecked())
refresh(1);
return null;
}
@Override
protected void onPostExecute(Void result) {
listview.onRefreshComplete();
}
}.execute(null, null, null);
}
});
inflater = getActivity().getLayoutInflater();
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(), 1000);
}
}.start();
// new Thread() {
// public void run() {
// utime.schedule(new detectUp(), 1000,4000);
// }
// }.start();
//
return rootView;
}
public void taskupload(addrecordBus event)
{
//上传后自动刷新
// if(event.getT())
// afterUpload();
}
public void afterUpload()
{
rbHistory.setChecked(true);
rbHistory.callOnClick();
}
@Override
public void onDestroyView() {
if(timer!=null){
timer.cancel();
}
if(ptimer != null)
ptimer.cancel();
if(dtimer != null)
dtimer.cancel();
// btLoading.cancel();
super.onDestroyView();
}
private class MyLeaveRecordsListTask extends TimerTask {
int type=0;
public MyLeaveRecordsListTask(){}
public MyLeaveRecordsListTask(int type){
this.type = type;
}
@Override
public void run() {
handler.sendEmptyMessage(4);
new testReqSearch(type).execute();
}
}
public void loadingData(){
btLoading = new Dialog(getActivity(), R.style.DialogStyle);
btLoading.requestWindowFeature(Window.FEATURE_NO_TITLE);
btLoading.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
btLoading.setContentView(R.layout.data_loading);
btLoading.setCanceledOnTouchOutside(false);
btLoading.show();
}
public void refresh(int typ)
{
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
{
switch(typ)
{
case 1:
//down
dataType = "down";
break;
default:
// dataType="upload";
break;
}
if(canFresh)
{
//SearchLines.getAssignByUser(sp.getString("ID", ""));
new testReqDown(1).execute();
canFresh = false;
}
new Thread() {
public void run() {
try {
Thread.sleep(3000);
canFresh = true;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
else
new testReqSearch().execute();
}
#7
public class Adapter extends BaseAdapter {
LayoutInflater inflater;
List<String> array;
private ImageButton curDel_btn;
private TextView mtv2;
private float x, ux;
public Adapter(LayoutInflater inf, List<String> arry) {
this.inflater = inf;
this.array = arry;
}
@Override
public int getCount() {
return array.size();
}
@Override
public Object getItem(int position) {
return array.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = inflater.inflate(R.layout.adapter_listview,parent,false);
vh.tv1 = (TextView) convertView.findViewById(R.id.textView1);
vh.tv1.setTextColor(Color.BLACK);
vh.tv2 = (TextView) convertView.findViewById(R.id.textView2);
vh.tv2.setTextColor(Color.BLACK);
vh.tv4 = (TextView) convertView.findViewById(R.id.textView3);
vh.tv4.setTextColor(Color.BLACK);
vh.tv3 = (TextView) convertView.findViewById(R.id.textView4);
vh.tv3.setTextColor(Color.BLACK);
//vh.del = (ImageButton) convertView.findViewById(R.id.del);
convertView.setTag(vh);
}
vh = (ViewHolder) convertView.getTag();
convertView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
final ViewHolder holder = (ViewHolder) v.getTag();
// 当按下时处理
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// 设置背景为选中状态
//v.setBackgroundResource(R.drawable.mm_listitem_pressed);
// 获取按下时的x轴坐标
//x = event.getX();
// 判断之前是否出现了删除按钮如果存在就隐藏
if (curDel_btn != null) {
//curDel_btn.setVisibility(View.GONE);
//mtv2.setVisibility(View.VISIBLE);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {// 松开处理
// 设置背景为未选中正常状态
//v.setBackgroundResource(R.drawable.mm_listitem_normal);
// 获取松开时的x坐标
//ux = event.getX();
// 判断当前项中按钮控件不为空时
if (holder.del != null) {
// 按下和松开绝对值差当大于20时显示删除按钮,否则不显示
if (Math.abs(x - ux) > 10) {
//holder.del.setVisibility(View.VISIBLE);
//holder.tv2.setVisibility(View.GONE);
//curDel_btn = holder.del;
//mtv2 = holder.tv2;
} else {
if(array.size()>0)
{
Intent intent = new Intent(
getActivity(),
AddRecord.class);
intent.putExtra("ids", array.get(position));
intent.putExtra("ind", position);
Toast.makeText(getActivity(), ""+position,Toast.LENGTH_LONG).show();
Log.d("Array", array.get(position));
Log.d("Position", ""+position);
intent.putExtra("record_type", "update");
//startActivityForResult(intent, OTHER);
//getActivity().overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
//getActivity().overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
//getActivity().finish();
}
}
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {// 当滑动时背景为选中状态
//v.setBackgroundResource(R.drawable.mm_listitem_pressed);
} else {// 其他模式
// 设置背景为未选中正常状态
//v.setBackgroundResource(R.drawable.mm_listitem_normal);
}
return true;
}
});
// //vh.del.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// if (curDel_btn != null)
// curDel_btn.setVisibility(View.GONE);
//// Dao dao = new Dao(getActivity());
// //LocationService ls = new LocationService();
// //ls.getNewdb();
//// if(dao.deleteId(CPCUtil.getPositionObj(array.get(position))[19]) == 1){
//// new testReqSearch().execute();
//// }
// }
// });
if(array.size() >= position)
{
// vh.tv1.setText("test");
// vh.tv2.setText("test");
// vh.tv3.setText("test");
// vh.tv4.setText("test");
if(CPCUtil.getStatu(array.get(position)).equals("2"))
{
// vh.tv1.setTextColor(Color.RED);
// vh.tv2.setTextColor(Color.RED);
vh.tv3.setTextColor(Color.RED);
// vh.tv4.setTextColor(Color.RED);
vh.tv1.setText(CPCUtil.getSeq(array.get(position))+") ");
vh.tv4.setText(" "+ CPCUtil.getPositionObj(array.get(position))[18]);
vh.tv2.setText(CPCUtil.getTime(array.get(position)));
if(array.size() > 0)
vh.tv3.setText("1".equals(CPCUtil.getStatu(array.get(position)))?"已上傳":"2".equals(CPCUtil.getStatu(array.get(position)))?"已下載":"3".equals(CPCUtil.getStatu(array.get(position)))?"已完成":"上傳中");
}
else
{
vh.tv1.setText(CPCUtil.getSeq(array.get(position))+") ");
vh.tv4.setText(" "+CPCUtil.getPositionObj(array.get(position))[18]);
vh.tv2.setText(CPCUtil.getTime(array.get(position)));
if(array.size() > 0)
vh.tv3.setText("1".equals(CPCUtil.getStatu(array.get(position)))?"已上傳":"2".equals(CPCUtil.getStatu(array.get(position)))?"已下載":"3".equals(CPCUtil.getStatu(array.get(position)))?"已完成":"上傳中");
}
}
return convertView;
}
class ViewHolder {
TextView tv1, tv2, tv3,tv4;
ImageButton del;
}
}
public void diSpan()
{
String[] mItems = {" 全部"," 已完成"," 已下載"};
ArrayAdapter<String> _Adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, mItems);
_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spScreen.setAdapter(_Adapter);
spScreen.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
//默认排序
case 0:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(0), 0);
}
}.start();
break;
//已完成
case 1:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(1), 0);
}
}.start();
break;
//上传中
case 2:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(4), 0);
}
}.start();
break;
}}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
public void hiSpan()
{
String[] mItems = {" 全部"," 上傳中"," 已上傳"};
ArrayAdapter<String> _Adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, mItems);
_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spScreen.setAdapter(_Adapter);
spScreen.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
//默认排序
case 0:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(0), 0);
}
}.start();
break;
//已完成
case 1:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(2), 0);
}
}.start();
break;
//上传中
case 2:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(3), 0);
}
}.start();
break;
}}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
LayoutInflater inflater;
List<String> array;
private ImageButton curDel_btn;
private TextView mtv2;
private float x, ux;
public Adapter(LayoutInflater inf, List<String> arry) {
this.inflater = inf;
this.array = arry;
}
@Override
public int getCount() {
return array.size();
}
@Override
public Object getItem(int position) {
return array.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = inflater.inflate(R.layout.adapter_listview,parent,false);
vh.tv1 = (TextView) convertView.findViewById(R.id.textView1);
vh.tv1.setTextColor(Color.BLACK);
vh.tv2 = (TextView) convertView.findViewById(R.id.textView2);
vh.tv2.setTextColor(Color.BLACK);
vh.tv4 = (TextView) convertView.findViewById(R.id.textView3);
vh.tv4.setTextColor(Color.BLACK);
vh.tv3 = (TextView) convertView.findViewById(R.id.textView4);
vh.tv3.setTextColor(Color.BLACK);
//vh.del = (ImageButton) convertView.findViewById(R.id.del);
convertView.setTag(vh);
}
vh = (ViewHolder) convertView.getTag();
convertView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
final ViewHolder holder = (ViewHolder) v.getTag();
// 当按下时处理
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// 设置背景为选中状态
//v.setBackgroundResource(R.drawable.mm_listitem_pressed);
// 获取按下时的x轴坐标
//x = event.getX();
// 判断之前是否出现了删除按钮如果存在就隐藏
if (curDel_btn != null) {
//curDel_btn.setVisibility(View.GONE);
//mtv2.setVisibility(View.VISIBLE);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {// 松开处理
// 设置背景为未选中正常状态
//v.setBackgroundResource(R.drawable.mm_listitem_normal);
// 获取松开时的x坐标
//ux = event.getX();
// 判断当前项中按钮控件不为空时
if (holder.del != null) {
// 按下和松开绝对值差当大于20时显示删除按钮,否则不显示
if (Math.abs(x - ux) > 10) {
//holder.del.setVisibility(View.VISIBLE);
//holder.tv2.setVisibility(View.GONE);
//curDel_btn = holder.del;
//mtv2 = holder.tv2;
} else {
if(array.size()>0)
{
Intent intent = new Intent(
getActivity(),
AddRecord.class);
intent.putExtra("ids", array.get(position));
intent.putExtra("ind", position);
Toast.makeText(getActivity(), ""+position,Toast.LENGTH_LONG).show();
Log.d("Array", array.get(position));
Log.d("Position", ""+position);
intent.putExtra("record_type", "update");
//startActivityForResult(intent, OTHER);
//getActivity().overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
//getActivity().overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
//getActivity().finish();
}
}
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {// 当滑动时背景为选中状态
//v.setBackgroundResource(R.drawable.mm_listitem_pressed);
} else {// 其他模式
// 设置背景为未选中正常状态
//v.setBackgroundResource(R.drawable.mm_listitem_normal);
}
return true;
}
});
// //vh.del.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// if (curDel_btn != null)
// curDel_btn.setVisibility(View.GONE);
//// Dao dao = new Dao(getActivity());
// //LocationService ls = new LocationService();
// //ls.getNewdb();
//// if(dao.deleteId(CPCUtil.getPositionObj(array.get(position))[19]) == 1){
//// new testReqSearch().execute();
//// }
// }
// });
if(array.size() >= position)
{
// vh.tv1.setText("test");
// vh.tv2.setText("test");
// vh.tv3.setText("test");
// vh.tv4.setText("test");
if(CPCUtil.getStatu(array.get(position)).equals("2"))
{
// vh.tv1.setTextColor(Color.RED);
// vh.tv2.setTextColor(Color.RED);
vh.tv3.setTextColor(Color.RED);
// vh.tv4.setTextColor(Color.RED);
vh.tv1.setText(CPCUtil.getSeq(array.get(position))+") ");
vh.tv4.setText(" "+ CPCUtil.getPositionObj(array.get(position))[18]);
vh.tv2.setText(CPCUtil.getTime(array.get(position)));
if(array.size() > 0)
vh.tv3.setText("1".equals(CPCUtil.getStatu(array.get(position)))?"已上傳":"2".equals(CPCUtil.getStatu(array.get(position)))?"已下載":"3".equals(CPCUtil.getStatu(array.get(position)))?"已完成":"上傳中");
}
else
{
vh.tv1.setText(CPCUtil.getSeq(array.get(position))+") ");
vh.tv4.setText(" "+CPCUtil.getPositionObj(array.get(position))[18]);
vh.tv2.setText(CPCUtil.getTime(array.get(position)));
if(array.size() > 0)
vh.tv3.setText("1".equals(CPCUtil.getStatu(array.get(position)))?"已上傳":"2".equals(CPCUtil.getStatu(array.get(position)))?"已下載":"3".equals(CPCUtil.getStatu(array.get(position)))?"已完成":"上傳中");
}
}
return convertView;
}
class ViewHolder {
TextView tv1, tv2, tv3,tv4;
ImageButton del;
}
}
public void diSpan()
{
String[] mItems = {" 全部"," 已完成"," 已下載"};
ArrayAdapter<String> _Adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, mItems);
_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spScreen.setAdapter(_Adapter);
spScreen.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
//默认排序
case 0:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(0), 0);
}
}.start();
break;
//已完成
case 1:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(1), 0);
}
}.start();
break;
//上传中
case 2:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(4), 0);
}
}.start();
break;
}}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
public void hiSpan()
{
String[] mItems = {" 全部"," 上傳中"," 已上傳"};
ArrayAdapter<String> _Adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, mItems);
_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spScreen.setAdapter(_Adapter);
spScreen.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch(position){
//默认排序
case 0:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(0), 0);
}
}.start();
break;
//已完成
case 1:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(2), 0);
}
}.start();
break;
//上传中
case 2:
if(timer!=null){
timer.cancel();
timer = new Timer();
}
new Thread() {
public void run() {
timer.schedule(new MyLeaveRecordsListTask(3), 0);
}
}.start();
break;
}}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
#8
Handler handler1 = new Handler(){
public void handleMessage(android.os.Message msg) {
String showMessage = "";
switch (msg.what) {
case GETWSDLRESULT:
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
// showMessage = "WSDL: " + GetResult;
// Toast.makeText(getActivity(), GetResult, Toast.LENGTH_LONG).show();
// EnvironmentShare.showToast(Main.this, showMessage);
break;
case 1:
rbDistribute.callOnClick();
break;
case 2:
rbHistory.callOnClick();
break;
case 3:
diSpan();
break;
case 4:
hiSpan();
break;
default:
break;
}
// 显示提示信息并 设置标题
// EnvironmentShare.showTitle(Main.this, showMessage, true);
// GetResult = "";
};
};
/*
public interface ICallback {
void execute(Vector<Object> obj,int nType);
}
ICallback listen1 = new ICallback(){
public void execute(Vector <Object> mResult,int nType)
{
switch (nType) {
case GETWSDLRESULT:
records = mResult;
handler1.sendEmptyMessage(GETWSDLRESULT);
// Toast.makeText(getActivity(), GetResult, Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
};
*/
//*****************************************************************
class testReqSearch extends AsyncTask<Void, Void, Void> {
int type = 0;
public testReqSearch(){}
public testReqSearch(int type){
this.type = type;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... params) {
Dao dao = new Dao(getActivity());
List<TaskInfo> tasks = new ArrayList<TaskInfo>();
if("down".equals(dataType)){
tasks = dao.getAllArrayOnDown(type);
} else if("upload".equals(dataType)){
tasks = dao.getAllArrayOnUpload(type);
}
array.clear();
tem.clear();
if(tasks!=null && tasks.size()>0){
obj = new Object[tasks.size()];
for(int i=0; i<tasks.size(); i++){
StringBuilder sb = new StringBuilder();
sb.append(tasks.get(i).getTaskID()).append("^").append(tasks.get(i).getType()).append("^")
.append(tasks.get(i).getCreateDate()).append("^").append("").append("^")
.append(tasks.get(i).getRecord()).append("^").append(tasks.get(i).getPhotoUrl()).append("^")
.append(tasks.get(i).getRecordUrl()).append("^").append("").append("^")
.append(tasks.get(i).getPhotoName()).append("^").append(tasks.get(i).getRecordName()).append("^")
.append(tasks.get(i).getLongitude()).append("^").append(tasks.get(i).getLatitude()).append("^")
.append(tasks.get(i).getUserId()).append("^").append(tasks.get(i).getCity()).append("^")
.append(tasks.get(i).getArea()).append("^").append(tasks.get(i).getStreet()).append("^")
.append(tasks.get(i).getAddress()).append("^").append(tasks.get(i).getStatus()).append("^")
.append(tasks.get(i).getTaskNum()).append("^").append(tasks.get(i).getId()).append("^").append(tasks.get(i).getSeq());
obj[i] = sb.toString();
array.add(sb.toString());
sb = null;
}
if(array.size()>0)
{
for(int b = array.size() -1; b >= 0; b--)
{
tem.add(array.get(b));
}
}
}
if(tem.size() >0)
adapterRecords = new Adapter(inflater, tem);
handler.sendEmptyMessage(3);
if("down".equals(dataType))
handler.sendEmptyMessage(7);
if("upload".equals(dataType))
handler.sendEmptyMessage(6);
return null;
}
}
class testReqDown extends AsyncTask<Void, Void, Void> {
int reqType = 0;
public testReqDown(int reqType){
this.reqType = reqType;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... params) {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
{
dao = new Dao(getActivity());
if(reqType == 1){
record = SearchLines.getAssignByUser(sp.getString("ID", ""));
}
if((record != null) && (record.size()>0)){
obj = new Object[record.size()];
for(Object obj : record){
String[] objs = CPCUtil.getPositionObj(obj.toString());
Object[] datas = new Object[20];
datas[0] = null;
datas[1] = 6;
datas[2] = objs[2];
datas[3] = objs[12];
datas[4] = objs[4];
datas[5] = objs[5];
datas[6] = objs[6];
datas[7] = objs[8];
datas[8] = objs[9];
datas[9] = objs[13];
datas[10] = objs[14];
datas[11] = objs[15];
datas[12] = objs[16];
datas[13] = objs[17];
// datas[20] = null;
if(!"".equals(datas[5]) && !"".equals(datas[6])){
datas[14] = datas[5]+","+datas[6]+",";
} else if(!"".equals(EntityConfig.obj[5]) && "".equals(datas[6])){
datas[14] = datas[5];
} else if("".equals(EntityConfig.obj[5]) && !"".equals(datas[6])){
datas[14] = datas[6];
} else {
datas[14] = "";
}
datas[15] = objs[0];
datas[16] = objs[11];
datas[17] = objs[10];
datas[18] = objs[18];
if(dao.getNumber() != 0)
{
seq = dao.getNumber();
datas[19] = seq + 1;
}
else
datas[19] = 1;
if(dao != null) // Modify by yx @ 20140719 dao == null ?
dao.toRecordInsert(datas, datas[15]);
}
}
}
if(array.size()!=0)
adapterRecords = new Adapter(inflater, array);
// handler.sendEmptyMessage(3);
new testReqSearch().execute(null,null,null);
return null;
}
}
}
public void handleMessage(android.os.Message msg) {
String showMessage = "";
switch (msg.what) {
case GETWSDLRESULT:
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
new testReqDown(0).execute();
// showMessage = "WSDL: " + GetResult;
// Toast.makeText(getActivity(), GetResult, Toast.LENGTH_LONG).show();
// EnvironmentShare.showToast(Main.this, showMessage);
break;
case 1:
rbDistribute.callOnClick();
break;
case 2:
rbHistory.callOnClick();
break;
case 3:
diSpan();
break;
case 4:
hiSpan();
break;
default:
break;
}
// 显示提示信息并 设置标题
// EnvironmentShare.showTitle(Main.this, showMessage, true);
// GetResult = "";
};
};
/*
public interface ICallback {
void execute(Vector<Object> obj,int nType);
}
ICallback listen1 = new ICallback(){
public void execute(Vector <Object> mResult,int nType)
{
switch (nType) {
case GETWSDLRESULT:
records = mResult;
handler1.sendEmptyMessage(GETWSDLRESULT);
// Toast.makeText(getActivity(), GetResult, Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
};
*/
//*****************************************************************
class testReqSearch extends AsyncTask<Void, Void, Void> {
int type = 0;
public testReqSearch(){}
public testReqSearch(int type){
this.type = type;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... params) {
Dao dao = new Dao(getActivity());
List<TaskInfo> tasks = new ArrayList<TaskInfo>();
if("down".equals(dataType)){
tasks = dao.getAllArrayOnDown(type);
} else if("upload".equals(dataType)){
tasks = dao.getAllArrayOnUpload(type);
}
array.clear();
tem.clear();
if(tasks!=null && tasks.size()>0){
obj = new Object[tasks.size()];
for(int i=0; i<tasks.size(); i++){
StringBuilder sb = new StringBuilder();
sb.append(tasks.get(i).getTaskID()).append("^").append(tasks.get(i).getType()).append("^")
.append(tasks.get(i).getCreateDate()).append("^").append("").append("^")
.append(tasks.get(i).getRecord()).append("^").append(tasks.get(i).getPhotoUrl()).append("^")
.append(tasks.get(i).getRecordUrl()).append("^").append("").append("^")
.append(tasks.get(i).getPhotoName()).append("^").append(tasks.get(i).getRecordName()).append("^")
.append(tasks.get(i).getLongitude()).append("^").append(tasks.get(i).getLatitude()).append("^")
.append(tasks.get(i).getUserId()).append("^").append(tasks.get(i).getCity()).append("^")
.append(tasks.get(i).getArea()).append("^").append(tasks.get(i).getStreet()).append("^")
.append(tasks.get(i).getAddress()).append("^").append(tasks.get(i).getStatus()).append("^")
.append(tasks.get(i).getTaskNum()).append("^").append(tasks.get(i).getId()).append("^").append(tasks.get(i).getSeq());
obj[i] = sb.toString();
array.add(sb.toString());
sb = null;
}
if(array.size()>0)
{
for(int b = array.size() -1; b >= 0; b--)
{
tem.add(array.get(b));
}
}
}
if(tem.size() >0)
adapterRecords = new Adapter(inflater, tem);
handler.sendEmptyMessage(3);
if("down".equals(dataType))
handler.sendEmptyMessage(7);
if("upload".equals(dataType))
handler.sendEmptyMessage(6);
return null;
}
}
class testReqDown extends AsyncTask<Void, Void, Void> {
int reqType = 0;
public testReqDown(int reqType){
this.reqType = reqType;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@Override
protected Void doInBackground(Void... params) {
if((ma.getAccess()) && (!(sp.getString("ID","").equals("serverdown"))))
{
dao = new Dao(getActivity());
if(reqType == 1){
record = SearchLines.getAssignByUser(sp.getString("ID", ""));
}
if((record != null) && (record.size()>0)){
obj = new Object[record.size()];
for(Object obj : record){
String[] objs = CPCUtil.getPositionObj(obj.toString());
Object[] datas = new Object[20];
datas[0] = null;
datas[1] = 6;
datas[2] = objs[2];
datas[3] = objs[12];
datas[4] = objs[4];
datas[5] = objs[5];
datas[6] = objs[6];
datas[7] = objs[8];
datas[8] = objs[9];
datas[9] = objs[13];
datas[10] = objs[14];
datas[11] = objs[15];
datas[12] = objs[16];
datas[13] = objs[17];
// datas[20] = null;
if(!"".equals(datas[5]) && !"".equals(datas[6])){
datas[14] = datas[5]+","+datas[6]+",";
} else if(!"".equals(EntityConfig.obj[5]) && "".equals(datas[6])){
datas[14] = datas[5];
} else if("".equals(EntityConfig.obj[5]) && !"".equals(datas[6])){
datas[14] = datas[6];
} else {
datas[14] = "";
}
datas[15] = objs[0];
datas[16] = objs[11];
datas[17] = objs[10];
datas[18] = objs[18];
if(dao.getNumber() != 0)
{
seq = dao.getNumber();
datas[19] = seq + 1;
}
else
datas[19] = 1;
if(dao != null) // Modify by yx @ 20140719 dao == null ?
dao.toRecordInsert(datas, datas[15]);
}
}
}
if(array.size()!=0)
adapterRecords = new Adapter(inflater, array);
// handler.sendEmptyMessage(3);
new testReqSearch().execute(null,null,null);
return null;
}
}
}
#9
我在下拉刷新的时候也遇到过类似的问题
我的解决办法 刷新之前不要清空list 当数据已经返回后 清空list 然后将新数据add进list中 然后notifyDataSetChanged
不知道这个方法适用楼主不 不过试试总没坏处
我的解决办法 刷新之前不要清空list 当数据已经返回后 清空list 然后将新数据add进list中 然后notifyDataSetChanged
不知道这个方法适用楼主不 不过试试总没坏处
#10
这个方法楼主可以尝试下。
#11
遇到了同样的问题,只看到异常反馈无法定位问题,楼主能重现么?在什么情况下发生?有解决了?
#12
数组越界,最好做一个为大小为0时处理一下!