При создании RecyclerView
в Tabhost
макете (например, в главном Messenger Activity
) я должен сделать Activity
с RecyclerView
для каждой вкладки или просто использовать основной Activity
и просто обратиться кодна вкладка?пакет com.example.aboomar.massengerme;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TabHost;
import adapters.MyHorizontalAdapter;
import adapters.MyVerticalAdapter;
import models.ModelVertical;
import models.ModelsHorizontal;
public class MainActivity extends AppCompatActivity {
RecyclerView verticalRecyclerView , horizontalRecyclerView;
TabHost host;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
verticalRecyclerView = findViewById(R.id.verticalRecycler);
horizontalRecyclerView = findViewById(R.id.storiesRecycler);
BottomNavigationView bottomNavigationView= findViewById(R.id.bottomNv);
bottomNavigationView.setItemIconSize(100);
host = findViewById(R.id.tabHost);
host.setup();
TabHost.TabSpec spec = host.newTabSpec("Messages");
spec.setContent(R.id.tab1);
spec.setIndicator("Messages");
host.addTab(spec);
host.setHorizontalScrollBarEnabled(true);
host.setup();
spec = host.newTabSpec("Active");
spec.setContent(R.id.tab2);
spec.setIndicator("Active");
host.addTab(spec);
spec = host.newTabSpec("Groups");
spec.setContent(R.id.tab3);
spec.setIndicator("Groups");
host.addTab(spec);
spec = host.newTabSpec("Calls");
spec.setContent(R.id.tab4);
spec.setIndicator("Calls");
host.addTab(spec);
// ***** Assigning Vertical Recycler Data
ModelVertical[] modelVerticals = {new ModelVertical(R.drawable.ahmed ,
"Ahmed" , "Mahmoud It's Me Ahmed " , "Thursday" , R.drawable.ahmed),
new ModelVertical(R.drawable.aly , "Aly" , "Hello Mahmous It's Me Aly" ,
"Tuesday" , R.drawable.aly),
new ModelVertical(R.drawable.elaayek , "Elaayeek" , "Hello Mahmoud It's Me
Elaayek" , "Monday" , R.drawable.elaayek),
new ModelVertical(R.drawable.fathy , " Fathy" , "Hello Mahmoud It's Me
Fathy", "Sunday" , R.drawable.fathy),
new ModelVertical(R.drawable.samy , " Samy" , "Hello Mahmoud It's Me
Samy", "Saturday" , R.drawable.samy),
new ModelVertical(R.drawable.wael , " Wael" , "Hello Mahmoud It's Me
Wael", "Wednesday" , R.drawable.wael)
};
ModelsHorizontal[] modelsHorizontals = {new
ModelsHorizontal(R.drawable.ic_camera2 , " Add to your story"),
new ModelsHorizontal(R.drawable.ahmed , "Ahmed"),
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.elaayek , " Elaayek "),
new ModelsHorizontal(R.drawable.ibraheem , " Ibrahim" ) ,
new ModelsHorizontal(R.drawable.omar , "Omar")
};
verticalRecyclerView.setLayoutManager(new LinearLayoutManager(this)
MyVerticalAdapter myAdapter = new MyVerticalAdapter(modelVerticals);
verticalRecyclerView.setAdapter(myAdapter);
horizontalRecyclerView.setLayoutManager(new LinearLayoutManager(this ,
LinearLayoutManager.HORIZONTAL , false));
MyHorizontalAdapter myHorizontalAdapter = new
MyHorizontalAdapter(modelsHorizontals);
horizontalRecyclerView.setAdapter(myHorizontalAdapter);
}
}