如何隐藏整个RecyclerView?

时间:2015-07-11 08:35:19

标签: android android-layout android-recyclerview

我试图隐藏RecyclerView,直到用户传递了一些有效信息。但它没有发生。当我尝试这个时会发生一些奇怪的事情,但它并没有显示任何错误。

这是我的代码:

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);
    }
}

我正在使用Paper作为我的数据库。

0 个答案:

没有答案