我有这个问题,我使用SlidingTab创建了一个带有3个标签的应用程序,在此选项卡的第二个中我有2个ListView,在第一个标签中我使用了ACTION_CAPTURE。 当从相机应用程序返回到主活动并且我在第二个选项卡中传递时,列表视图都消失了。 为什么呢?
答案 0 :(得分:0)
import arrivi.operativi.operativi220.InventarioAdapter.customButtonListener;
import arrivi.operativi.operativi220.invepiazzadapter.customButtonListener2;
public class InventarioFragment extends Fragment implements customButtonListener, customButtonListener2 {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
int entrata=0;
private WritableCellFormat timesBoldUnderline;
private WritableCellFormat times;
Button btNew ;
globalVar g;
inv_list lista = inv_list.getInstance();
inv_list_piaz lista_piaz = inv_list_piaz.getInstance();
ArrayList<inventario> ls = new ArrayList<>();
ArrayList<inventariopiazzale> lsp = new ArrayList<>();
inventario tmpINV;
inventariopiazzale tmpINVP;
ListView lv;
ListView lvp;
invepiazzadapter adapter_piazz;
InventarioAdapter adapter;
public static InventarioFragment newInstance(int page) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
InventarioFragment fragment = new InventarioFragment();
fragment.setArguments(args);
return fragment;
}
//@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPage = getArguments().getInt(ARG_PAGE);
setHasOptionsMenu(true);
//setMenuBar();
if (entrata == 0) {
popola_array();
entrata = 1;
}
//ls=lista.getInventarioArrayList();
Context context = getActivity().getApplicationContext();
adapter = new InventarioAdapter(context, R.layout.layout_inventario, lista.getInventarioArrayList());
adapter.setCustomButtonListner(new customButtonListener() {
@Override
public void onButtonClickListner(int position, inventario value, RadioGroup rR, int numAR) {
if (numAR == 1) {
Toast.makeText(getActivity(), "Scelta Rimossa! " + position,
Toast.LENGTH_SHORT).show();
inventario p;
p = value;
rR.clearCheck();
inv_list locale = inv_list.getInstance();
ArrayList<inventario> tmp = locale.getInventarioArrayList();
p.setPorta(String.valueOf(p.getPosizione() + 1));
p.setsR(0);
p.setcM(0);
p.setrM(0);
p.setTarga("");
tmp.set(p.getPosizione(), p);
locale.setInventarioArrayList(tmp);
}
}
});
adapter_piazz = new invepiazzadapter(context,R.layout.layout_inventario,lista_piaz.getInventarioArrayList());
adapter_piazz.setCustomButtonListner2(new customButtonListener2() {
@Override
public void onButtonClickListner2(int position, inventariopiazzale iv, RadioGroup rR, int numAR) {
if (numAR == 2) {
inventariopiazzale Pi;
Pi = iv;
rR.clearCheck();
inv_list_piaz locale = inv_list_piaz.getInstance();
ArrayList<inventariopiazzale> tmp2 = locale.getInventarioArrayList();
Pi.setPorta(String.valueOf(Pi.getPosizione() + 1));
//btRM.setChecked(false);
// btCM.setChecked(false);
// btSR.setChecked(false);
Pi.setsR(0);
Pi.setcM(0);
Pi.setrM(0);
Pi.setTarga("");
tmp2.set(Pi.getPosizione(), Pi);
locale.setInventarioArrayList(tmp2);
Toast.makeText(getActivity(), "Scelta Rimossa! " + Pi.getPorta(),
Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_inventario, container, false);
setMenuBar();
btNew = (Button) view.findViewById(R.id.buttonNew);
lv = (ListView) view.findViewById(R.id.LVRibalte);
lvp = (ListView) view.findViewById(R.id.lvPiazzale);
lv.setAdapter(adapter);
lvp.setAdapter(adapter_piazz);
//setMenuBar();
setLayout(view);
return view;
}
// Config Layout
public void setLayout(View v)
{
// Inizializzo Titolo List
TextView LabTop = (TextView) v.findViewById(R.id.Inv_Rib_Label);
Typeface carLabTop = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Sportscenter.ttf");
LabTop.setTextColor(Color.BLACK);
LabTop.setTextSize(18);
LabTop.setTypeface(carLabTop);
TextView LabButtom = (TextView) v.findViewById(R.id.textView4);
Typeface carLabButom = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Sportscenter.ttf");
LabButtom.setTextColor(Color.BLACK);
LabButtom.setTextSize(18);
LabButtom.setTypeface(carLabButom);
// Inizializzo le listview
/** TextView EdTarga = (EditText) v.findViewById(R.id.num_Porta);
Typeface carTarga= Typeface.createFromAsset(getActivity().getAssets(), "fonts/Sportscenter.ttf");
EdTarga.setTextColor(Color.BLACK);
EdTarga.setTextSize(18);
EdTarga.setTypeface(carTarga);**/
}
// INIZIO TEST ZONE
public void crea_file_excel(){
final String fileName = "inventario.xls";
File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/OA");
if(!directory.isDirectory()){
directory.mkdirs();
}
File file = new File(directory, fileName);
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("it", "IT"));
WritableWorkbook workbook;
try {
workbook = Workbook.createWorkbook(file, wbSettings);
WritableSheet sheet = workbook.createSheet("Invantario Piazzale", 0);
try {
sheet.addCell(new Label(0,0,"Porta"));
//sheet.addCell(new WritableCellFormat().setBorder(Border.BOTTOM, BorderLineStyle.DASHED));
sheet.addCell(new Label(1,0,"Tipo Pezzo"));
sheet.addCell(new Label(2,0,"Targa"));
int conta = 1;
for (int i = 0; i < ls.size(); i++) {
tmpINV = ls.get(i);
sheet.addCell(new Label(0, conta, tmpINV.getPorta()));
if((tmpINV.getrM() == 0) & (tmpINV.getsR() == 0) & (tmpINV.getcM() == 0))
{
sheet.addCell(new Label(1, conta, "Porta Vuota"));
sheet.addCell(new Label(2, conta, ""));
}
if(tmpINV.getsR() == 1)
{
sheet.addCell(new Label(1, conta, "Semi Rimorchio"));
sheet.addCell(new Label(2, conta, tmpINV.getTarga()));
}
if(tmpINV.getcM() == 1)
{
sheet.addCell(new Label(1, conta, "CASSA"));
sheet.addCell(new Label(2, conta, tmpINV.getTarga()));
}
if(tmpINV.getrM() == 1)
{
sheet.addCell(new Label(1, conta, "Rimorchio"));
sheet.addCell(new Label(2, conta, tmpINV.getTarga()));
}
conta = conta + 1;
}
for (int i = 0; i < lsp.size(); i++) {
tmpINVP = lsp.get(i);
sheet.addCell(new Label(0, conta, tmpINVP.getPorta()));
sheet.addCell(new Label(2, conta, tmpINVP.getTarga()));
if((tmpINVP.getrM() == 0) & (tmpINVP.getsR() == 0) & (tmpINVP.getcM() == 0))
{
}
if(tmpINVP.getsR() == 1)
{
sheet.addCell(new Label(1, conta, "Semi Rimorchio"));
sheet.addCell(new Label(2, conta, tmpINVP.getTarga()));
conta = conta + 1;
}
if(tmpINVP.getcM() == 1)
{
sheet.addCell(new Label(1, conta, "CASSA"));
sheet.addCell(new Label(2, conta, tmpINVP.getTarga()));
conta = conta + 1;
}
if(tmpINVP.getrM() == 1)
{
sheet.addCell(new Label(1, conta, "Rimorchio"));
sheet.addCell(new Label(2, conta, tmpINVP.getTarga()));
conta = conta + 1;
}
}
}catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
workbook.write();
try {
workbook.close();
} catch (WriteException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void onResume()
{
super.onResume();
}
public void onStart()
{
super.onStart();
//Fragment.onActivityCreated(Bundle);
this.onCreate(null);
}
// FINE TEST ZONE
public void popola_array()
{
RadioGroup RG=(RadioGroup) getActivity().findViewById( R.id.radioGroup);
globalVar ff = globalVar.getInstance();
int i =0;
int pP=ff.getPP();
int pR=ff.getPR();
for (i=0;i<pR;i++)
{
// View v = new View (R.layout.layout_inventario);
// RG.check(R.id.semiRimorchio);
ls.add(new inventario(String.valueOf(i+1),R.id.semiRimorchio,0,0,0,i,""));
}
inv_list tmp = inv_list.getInstance();
tmp.setInventarioArrayList(ls);
for (i=0;i<pP;i++)
{
lsp.add(new inventariopiazzale("P"+String.valueOf(i+1),R.id.semiRimorchio,0,0,0,i,""));
}
inv_list_piaz tmpp = inv_list_piaz.getInstance();
tmpp.setInventarioArrayList(lsp);
entrata =1;
}
public void conta_pezzi()
{
int tmpSR=0;
int tmpCM=0;
int tmpRM=0;
for (int i =0; i<ls.size();i++)
{
tmpINV = ls.get(i);
if(tmpINV.getcM()==1)
tmpCM =tmpCM+1;
if(tmpINV.getsR()==1)
tmpSR= tmpSR+1;
if(tmpINV.getrM()==1)
tmpRM=tmpRM+1;
}
int tmpSRP=0;
int tmpCMP=0;
int tmpRMP=0;
for (int i =0; i<lsp.size();i++)
{
tmpINVP = lsp.get(i);
if(tmpINVP.getcM()==1)
tmpCMP =tmpCMP+1;
if(tmpINVP.getsR()==1)
tmpSRP= tmpSRP+1;
if(tmpINVP.getrM()==1)
tmpRMP=tmpRMP+1;
}
Toast.makeText(getActivity(), "In ribalta: " + tmpCM +"CM, "+tmpSR +"SR, "+tmpRM+"Rim., a Piazzale :"+ tmpCMP +"CM, "+tmpSRP +"SR, "+tmpRMP+"Rim." , Toast.LENGTH_LONG).show();
}
@Override
public void onButtonClickListner(int position, inventario value, RadioGroup rR, int numAR) {
if (numAR == 1) {
Toast.makeText(getActivity(), "Scelta Rimossa! " + position,
Toast.LENGTH_SHORT).show();
inventario p;
p = value;
rR.clearCheck();
inv_list locale = inv_list.getInstance();
ArrayList<inventario> tmp = locale.getInventarioArrayList();
p.setPorta(String.valueOf(p.getPosizione() + 1));
p.setsR(0);
p.setcM(0);
p.setrM(0);
p.setTarga("");
tmp.set(p.getPosizione(), p);
locale.setInventarioArrayList(tmp);
}
}
@Override
public void onButtonClickListner2(int position, inventariopiazzale iv, RadioGroup rR, int numAR) {
if (numAR == 2)
{
inventariopiazzale Pi ;
Pi = iv;
rR.clearCheck();
inv_list_piaz locale = inv_list_piaz.getInstance();
ArrayList<inventariopiazzale> tmp2 = locale.getInventarioArrayList();
Pi.setPorta(String.valueOf(Pi.getPosizione() + 1));
//btRM.setChecked(false);
// btCM.setChecked(false);
// btSR.setChecked(false);
Pi.setsR(0);
Pi.setcM(0);
Pi.setrM(0);
Pi.setTarga("");
tmp2.set(Pi.getPosizione(), Pi);
locale.setInventarioArrayList(tmp2);
Toast.makeText(getActivity(), "Scelta Rimossa! " + Pi.getPorta(),
Toast.LENGTH_SHORT).show();
}
}
public void onCreateOptionsMenu( Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.action_fragment, menu);
MenuItem add = menu.findItem(R.id.menu_add);
add.setVisible(false);
MenuItem setting = menu.findItem(R.id.menu_setting);
setting.setVisible(false);
MenuItem foto = menu.findItem(R.id.menu_foto);
foto.setVisible(false);
MenuItem send = menu.findItem(R.id.menu_inventario);
send.setShowAsAction(2);
setMenuBar();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.menu_inventario) {
Toast.makeText(getActivity(), "Invia Inventario!!", 2500).show();
return true;
}
return super.onOptionsItemSelected(item);
}
public void setMenuBar()
{
Typeface font2 = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Sportscenter.ttf");
SpannableStringBuilder SI = new SpannableStringBuilder("Inventario Pezzi");
SI.setSpan(new CustomTypefaceSpan("", font2), 0, SI.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
SI.setSpan(new ForegroundColorSpan(Color.WHITE),0, SI.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SI.setSpan(new RelativeSizeSpan(1.2f), 0,SI.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
((MainActivity) getActivity()).getActionBar().setTitle(SI);
}
}