片段的onItemClick将意图调用到另一个Activity。
onItemClick需要2-3秒的长时间。在onitemclick后,它在当前点击的屏幕上停留大约2-3,然后移动到活动。
而且重复移动到活动并返回按下后退按钮20次导致崩溃也没有日志 尝试过去2天调试。
没有运气请请帮助。
请找到以下代码 的 BatchListActivity.java
/ ** *由E0000099于08-09-2015创建。 * /
public class BatchListActivity extends BaseActivity {
private SlidingTabLayout tabs;
private ViewPager mViewPager;
private String[] tabNames = {"List", "Location"};
private ArrayList<AssetTaskCollectionModel> mAssetTaskCollectionModelList;
private BatchListViewPagerAdapter mBatchListViewAdapter;
private String mBatchNumber = null;
public static ArrayList<AssetTaskCollectionModel> mAssetTaskCollectionBatchAssetList = new ArrayList<AssetTaskCollectionModel>();
private CustomProgressDialog pDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
displayActionBar();
mBatchNumber = getIntent().getStringExtra("Batch Number");
if(mAssetTaskCollectionBatchAssetList.size() == 0) {
mAssetTaskCollectionBatchAssetList.size();
}
mAssetTaskCollectionBatchAssetList = MyListActivity.batchNumberListHashMap.get(mBatchNumber);
setActionBarTitle("Batch Number " + mBatchNumber);
tabs = (SlidingTabLayout) findViewById(R.id.tabs_batch_list);
tabs.setDistributeEvenly(true);
mViewPager = (ViewPager) findViewById(R.id.viewPager_batch_list);
mBatchListViewAdapter = new BatchListViewPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mBatchListViewAdapter);
tabs.setViewPager(mViewPager);
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.action_bar);
}
});
}
@Override
protected int getLayoutResource() {
return R.layout.activity_batch_list;
}
}
**BatchListFragment**
public class BatchListFragment extends Fragment implements AdapterView.OnItemClickListener {
private ArrayList<AssetTaskCollectionModel> mAssetTaskCollectionBatchList = new ArrayList<AssetTaskCollectionModel>();
private ListView mBatchNumberListView;
private EditText SearchEt;
private BatchListAdapter mBatchListAdapter;
@SuppressWarnings("unchecked")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_batch_list, container, false);
SearchEt = (EditText) view.findViewById(R.id.search_et);
mBatchNumberListView = (ListView) view.findViewById(R.id.batch_list);
new LoadListObjectsTask(getActivity()).execute();
return view;
}
@Override
public void onItemClick(final AdapterView<?> adapterView, View view, final int position, long l) {
// getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Common.isAssetManuallyVerified = true;
AssetTaskCollectionModel assetTaskCollectionModelObj = (AssetTaskCollectionModel) adapterView.getItemAtPosition(position);
Intent intent = new Intent(getActivity(), UpdateStatusActivity.class);
intent.putExtra("AssetDataObj", assetTaskCollectionModelObj);
getActivity().startActivity(intent);
}
});
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
getActivity().getMenuInflater().inflate(R.menu.addasset_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_scan:
checkIfAssetsArePresent();
return true;
case android.R.id.home:
getActivity().finish();
return true;
default:
break;
}
return false;
}
private void checkIfAssetsArePresent() {
Common.scanSearchFromTheList = true;
Common.scanFromAddAsset = false;
SharedPreferences sharedpreferences = getActivity().getSharedPreferences(DefaultSettingsActivity.MyPREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
if (sharedpreferences.getBoolean(DefaultSettingsActivity.CAMERA, true) &&
sharedpreferences.getBoolean(DefaultSettingsActivity.PHER, true)) {
ScanPopupDialog scanPopupDialog = new ScanPopupDialog(getActivity());
scanPopupDialog.show();
} else if (sharedpreferences.getBoolean(DefaultSettingsActivity.PHER, true)) {
CustomAlertDialog alertDialog = new CustomAlertDialog(getActivity(), "Info", "No Peripheral connected", "Ok", new CustomAlertDialog2Callback() {
@Override
public void onButtonClick3() {
}
});
alertDialog.show();
} else if (sharedpreferences.getBoolean(DefaultSettingsActivity.CAMERA, true)) {
Intent intentToScan = new Intent(getActivity(), ScanActivity.class);
startActivity(intentToScan);
}
}
private class LoadListObjectsTask extends AsyncTask<Void, List<AssetTaskCollectionModel>, Void> {
private Context mContext;
private LoadListObjectsTask(Context context){
this.mContext = context;
}
@Override
public Void doInBackground(Void... params) {
mBatchListAdapter = new BatchListAdapter(mContext, BatchListActivity.mAssetTaskCollectionBatchAssetList);
SearchEt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { }
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (TextUtils.isEmpty(charSequence)) {
mBatchListAdapter.clearFilter();
} else mBatchListAdapter.getFilter().filter(charSequence);
}
@Override
public void afterTextChanged(Editable editable) { }
});
return null;
}
@Override
public void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
mBatchNumberListView.setAdapter(mBatchListAdapter);
}
}
}
UpdateStatusActivty.java
public class UpdateStatusActivity extends BaseActivity implements View.OnClickListener {
private TextView fDescriptionValue, fAssetClassValue, fCompanyCodeValue, fSerialValue, fAssetValue, fLastinventoryValue,
fCapitializedValue, fCostCenterValue, fPlantValue, fLocationValue, fCurrentLocationValue, fSubdescription;
private AssetTaskCollectionModel mAssetModel;
private Button fTagAssetBtn;
private String mAddress;
private ImageView fLocationArrow;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAssetModel = (AssetTaskCollectionModel) getIntent().getSerializableExtra("AssetDataObj");
displayActionBar();
setActionBarTitle("Asset Data");
initializeViews();
setData();
}
private void initializeViews() {
fTagAssetBtn = (Button) findViewById(R.id.addassetButton);
fTagAssetBtn.setOnClickListener(this);
fDescriptionValue = (TextView) findViewById(R.id.description_value);
fAssetClassValue = (TextView) findViewById(R.id.assetclass_value);
fCompanyCodeValue = (TextView) findViewById(R.id.companycode_value);
fSerialValue = (TextView) findViewById(R.id.serial_value);
fAssetValue = (TextView) findViewById(R.id.asset_value);
fLastinventoryValue = (TextView) findViewById(R.id.lastinventory_value);
fCapitializedValue = (TextView) findViewById(R.id.capitialized_value);
fCostCenterValue = (TextView) findViewById(R.id.costcenter_value);
fPlantValue = (TextView) findViewById(R.id.plant_value);
fLocationValue = (TextView) findViewById(R.id.location_value);
fCurrentLocationValue = (TextView) findViewById(R.id.geolocation_value);
//description
fSubdescription = (TextView) findViewById(R.id.subdescription);
fLocationArrow = (ImageView) findViewById(R.id.locationArrow);
fLocationArrow.setOnClickListener(this);
}
private void setData()
{
fTagAssetBtn.setText("Update Status");
fSubdescription.setText(mAssetModel.getANLN1());
fDescriptionValue.setText(mAssetModel.getTXT50());
fAssetClassValue.setText(mAssetModel.getANLKL());
fCompanyCodeValue.setText(mAssetModel.getBUKRS());
//serial number
fSerialValue.setText(mAssetModel.getSERNR());
//tag number
fAssetValue.setText(mAssetModel.getINVNR());
fLastinventoryValue.setText(mAssetModel.getIVDAT());
fCapitializedValue.setText("");
fCostCenterValue.setText(mAssetModel.getKOSTL() + "\n");
fPlantValue.setText(mAssetModel.getWERKS() + "\n" + mAssetModel.getWERKSDESCRIPTION());
fLocationValue.setText(mAssetModel.getSTORT());
fCurrentLocationValue.setOnClickListener(this);
GPSService mGPSService = new GPSService(this);
mGPSService.getLocation();
if (!mGPSService.isLocationAvailable) {
Toast.makeText(this, "Your location is not available, please try again.", Toast.LENGTH_SHORT).show();
} else {
mAddress = mGPSService.getLocationAddress();
fCurrentLocationValue.setText(mAddress.substring(0, 12) + "...");
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected int getLayoutResource() {
return R.layout.activity_assetdata;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.addassetButton:
if (Common.isAssetManuallyVerified == true) {
Intent mIntentToUpdateStatus = new Intent(UpdateStatusActivity.this, UpdateStatusSubmitActivity.class);
mIntentToUpdateStatus.putExtra("BUKRS", fCompanyCodeValue.getText());
mIntentToUpdateStatus.putExtra("ANLN1", fSubdescription.getText());
mIntentToUpdateStatus.putExtra("ANLN2", mAssetModel.getANLN2());
mIntentToUpdateStatus.putExtra("BATCHNUMBER", mAssetModel.getBATCHNUMBER());
mIntentToUpdateStatus.putExtra("COMPLETIONSTATUS", mAssetModel.getCOMPLETIONSTATUS());
mIntentToUpdateStatus.putExtra("LVTNR", mAssetModel.getLVTNR());
mIntentToUpdateStatus.putExtra("LETXT", mAssetModel.getLETXT());
startActivity(mIntentToUpdateStatus);
} else {
Intent mIntentToUpdateStatus = new Intent(UpdateStatusActivity.this, UpdateStatusBarcodeSubmitActivity.class);
mIntentToUpdateStatus.putExtra("BUKRS", fCompanyCodeValue.getText());
mIntentToUpdateStatus.putExtra("ANLN1", fSubdescription.getText());
mIntentToUpdateStatus.putExtra("ANLN2", mAssetModel.getANLN2());
mIntentToUpdateStatus.putExtra("BATCHNUMBER", mAssetModel.getBATCHNUMBER());
mIntentToUpdateStatus.putExtra("COMPLETIONSTATUS", mAssetModel.getCOMPLETIONSTATUS());
mIntentToUpdateStatus.putExtra("LVTNR", mAssetModel.getLVTNR().toString());
mIntentToUpdateStatus.putExtra("LETXT", mAssetModel.getLETXT().toString());
startActivity(mIntentToUpdateStatus);
}
break;
case R.id.geolocation_value:
Intent intent = new Intent(this, DisplayLocationMap.class);
intent.putExtra("TAG", mAddress);
startActivity(intent);
break;
case R.id.locationArrow:
Intent intentToLocation = new Intent(this, DisplayLocationMap.class);
intentToLocation.putExtra("TAG", mAddress);
startActivity(intentToLocation);
break;
}
}
}
BatchListAdapter.java
public class BatchListAdapter extends BaseAdapter implements Filterable {
protected static final String TAG = "BatchListAdapter.java";
public Context context;
private ArrayList<AssetTaskCollectionModel> mAssetTaskCollectionBatchAssetList ;
private int mBacgroundColor;
private ArrayList<AssetTaskCollectionModel> mFiltereditemsList;
/**
* Contructor to pass the Reference
*
* @parama
*/
public BatchListAdapter(Context context, ArrayList<AssetTaskCollectionModel> mAssetTaskCollectionBatchAssetList) {
this.context = context;
mFiltereditemsList = mAssetTaskCollectionBatchAssetList ;
this.mAssetTaskCollectionBatchAssetList = mAssetTaskCollectionBatchAssetList;
}
public void clearFilter() {
mAssetTaskCollectionBatchAssetList = mFiltereditemsList;
notifyDataSetChanged();
}
@Override
public int getCount() {
return mAssetTaskCollectionBatchAssetList.size();
}
@Override
public AssetTaskCollectionModel getItem(int i) {
return mAssetTaskCollectionBatchAssetList.get(i);
}
static class ViewHolder {
TextView fAssetNoLabel, fAssetNoValue, fDescriptionLabel, fDescriptionValue,
fTagNoLabel,fTagNoValue, fSerialNoLabel, fSerialNoValue;
RelativeLayout fListBackground;
}
@Override
public long getItemId(int i) {
return i;
}
@SuppressLint("ViewHolder")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.batch_list_item, parent, false);
holder = new ViewHolder();
holder. fListBackground = (RelativeLayout) convertView.findViewById(R.id.main);
holder. fAssetNoLabel = (TextView) convertView.findViewById(R.id.asset_no_label);
holder. fAssetNoValue = (TextView) convertView.findViewById(R.id.asset_no_value);
holder. fDescriptionLabel = (TextView) convertView.findViewById(R.id.description_label);
holder. fDescriptionValue = (TextView) convertView.findViewById(R.id.description_value);
holder. fTagNoLabel = (TextView) convertView.findViewById(R.id.tag_no_label);
holder. fTagNoValue = (TextView) convertView.findViewById(R.id.tag_no_value);
holder. fSerialNoLabel = (TextView) convertView.findViewById(R.id.serial_no_label);
holder. fSerialNoValue = (TextView) convertView.findViewById(R.id.serial_no_value);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
AssetTaskCollectionModel mAssetTaskCollectionModelObj = getItem(position);
holder. fListBackground.setBackgroundColor( getListBackGroundColor(mAssetTaskCollectionModelObj));
holder. fAssetNoLabel.setText("Asset No: ");
holder. fDescriptionLabel.setText("Description: ");
holder. fTagNoLabel.setText("Tag No: ");
holder. fSerialNoLabel.setText("Serial No: ");
holder. fAssetNoValue.setText(mAssetTaskCollectionModelObj.getANLN1());
holder. fDescriptionValue.setText(mAssetTaskCollectionModelObj.getTXT50());
holder. fTagNoValue.setText(mAssetTaskCollectionModelObj.getINVNR());
holder. fSerialNoValue.setText(mAssetTaskCollectionModelObj.getSERNR());
return convertView;
}
@Override
public Filter getFilter() {
Filter filter = new Filter() {
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
mAssetTaskCollectionBatchAssetList = (ArrayList<AssetTaskCollectionModel>) results.values;
notifyDataSetChanged();
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if (!(constraint.toString().isEmpty())) {
ArrayList<AssetTaskCollectionModel> filteredList = new ArrayList<AssetTaskCollectionModel>();
constraint = constraint.toString().toLowerCase();
for (int i = 0; i < mFiltereditemsList.size(); i++) {
if (
mFiltereditemsList.get(i).getANLN1().toLowerCase().contains(constraint) ||
mFiltereditemsList.get(i).getTXT50().toLowerCase().contains(constraint) ||
mFiltereditemsList.get(i).getINVNR().toLowerCase().contains(constraint) ||
mFiltereditemsList.get(i).getSERNR().toLowerCase().contains(constraint)
) {
filteredList.add(mFiltereditemsList.get(i));
}
}
results.count = filteredList.size();
results.values = filteredList;
return results;
} else {
results.count = mFiltereditemsList.size();
results.values = mFiltereditemsList;
return results;
}
}
};
return filter;
}
public int getListBackGroundColor( AssetTaskCollectionModel mAssetTaskCollectionModelObj ) {
if (!mAssetTaskCollectionModelObj.getCOMPLETIONSTATUS().equalsIgnoreCase("00")) {
mBacgroundColor = context.getResources().getColor(R.color.list_view_green);
} else {
mBacgroundColor =context.getResources().getColor(R.color.list_view_transperent);
}
return mBacgroundColor;
}