How can I hide the entire RecyclerView?

I am trying to hide RecyclerView

until the user misses any valid information. But that doesn't happen. Some strange things happen when I try to do this, but it doesn't show any errors.

Here's my code:

MainActivity.java

public class MainActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private LinearLayout recyclerRow;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Paper.init(getApplicationContext());

        toolbar = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);

        getSupportActionBar().setDisplayShowHomeEnabled(true);
        NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), (Toolbar) findViewById(R.id.app_bar));

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.goalList);
        RVAdapter adapter = new RVAdapter(getApplicationContext(), getData());
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

        recyclerRow = (LinearLayout) findViewById(R.id.goal_row);
        if(Paper.get("goalTitle") == null){
            recyclerView.setVisibility(View.GONE);
            recyclerRow.setVisibility(View.GONE);
        }
    }


    public List<RVData> getData() {

        Log.d("Check6", Paper.get("goalTitle") + "");
        List<RVData> data = new ArrayList<>();
        String[] titles = {(String) Paper.get("goalTitle")};


        for (int i = 0; i < titles.length; i++) {
            RVData current = new RVData();
            current.goalTitle = titles[i];
            data.add(current);
        }

        return data;
    }



    public void newGoal(View view) {
        Intent intent = new Intent(MainActivity.this, NewGoal.class);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

      

I am using "Paper" for my database.

+3


source to share


1 answer


Instead of setVisibility, you can use setAlpha(0)

to hide and setAlpha(1)

display. This is what I ended up doing. It works well. This will have the same effect as using visibility Invisible

.



+1


source







All Articles