在单独的类和SetVisibility()问题中存储数据

时间:2019-06-23 15:32:11

标签: java android

我正在尝试使我的应用正常运行,但显然卡住了。首先,我有一个全局data.java文件,其中有一个静态表,但我也想在此存储一个数组,然后我将对它进行修改并从另一个java类读取。第二,当我尝试使用另一个类的SetVisibility()时,屏幕上什么也没有发生,但是我的Logcat说我的对象可见。

搜索filter.java

EditText editText = findViewById(R.id.actv);
                String wpisaneMiasto = editText.getText().toString();
                int i = 0;
                for (; i < data.miasta.length; i++){
                //    Log.w("Iter","" + data.miasta.length);
                //    Log.w("data.miasta","" + data.miasta[i]);
                    if (data.miasta[i].equals(wpisaneMiasto)){
                        Snackbar.make(v, "Miasto: " + data.miasta[i] + ", index: " + i, Snackbar.LENGTH_LONG).setAction("Action", null).show();
                        break;

                    }
                }
                Log.w("Input","" + wpisaneMiasto);

                data dane = new data();
                dane.OdwiedzoneMiasta[i] = 1;



                Intent intent = new Intent(SearchFilter.this, com.palidon.visitor.MainActivity.class);
                if( wpisaneMiasto.length() > 0 && data.miasta[i].equals(wpisaneMiasto)){
                    intent.putExtra("methodName",1);
                    intent.putExtra("MIASTO", i);
                }
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                finish();

                startActivity(intent);

data.java

public class data {

    public static String[] miasta;
    static {
        miasta = new String[935];
        miasta[0] = "Aleksandrów Kujawski (KP)";
        ...
        miasta[934] = "Żywiec (ŚL)";
    }
public int OdwiedzoneMiasta[];
    {
        OdwiedzoneMiasta = new int[935];
    }

MainActivity.java

public void AddIMG() {
        data dane = new data();
        int i = 0;
        for(; i < dane.OdwiedzoneMiasta.length; i++) {
            Log.i("Pętla w AddIMG", "" + dane.OdwiedzoneMiasta[i]);
            if (dane.OdwiedzoneMiasta[i] == 1) {

                LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View mapV = inflater.inflate(R.layout.fragment_map, null);
                // LayoutInflater inflater = (LayoutInflater)MainActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                // View view = inflater.inflate(R.layout.fragment_map, null);
                // setContentView(R.layout.activity_main);
                Log.w("AddIMG()", "Modyfikacja obrazu");
                //setContentView(R.layout.activity_main);
                ImageView myImage = mapV.findViewById(R.id.miasto_162);
                Log.e("IsItReallyNull?", "" + myImage);
                //ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) myImage.getLayoutParams();
                //marginParams.setMargins(50,0,0,0);
                Log.i("IsVisible?", "" + myImage.getVisibility());
                myImage.setVisibility(View.VISIBLE);
                Log.i("IsVisible??", "" + myImage.getVisibility());
                refreshView(mapV);
                //myImage.refreshDrawableState();
                //mapV.refreshDrawableState();
                //inflater.inflate(R.layout.activity_main,null);
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MapFragment()).commit();
            }
        }
    }

我的目标是能够动态编辑OdwiedzoneMiasta []数组并让SetVisibility()正常工作

0 个答案:

没有答案