2.1. Dependências
dependencies {
...
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.material:material:1.1.0'
}
2.2. MainActivity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new WeatherAdapter(getSampleData()));
}
private List getSampleData() {
List weatherList = new ArrayList<>();
// Adicione exemplos de dados aqui
return weatherList;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_about) {
Intent intent = new Intent(this, AboutActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
2.3. RecyclerView Adapter
public class WeatherAdapter extends RecyclerView.Adapter {
private List weatherList;
public WeatherAdapter(List weatherList) {
this.weatherList = weatherList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.weather_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Weather weather = weatherList.get(position);
// Configure os dados do item aqui
}
@Override
public int getItemCount() {
return weatherList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
// Inicialize os componentes do item aqui
public ViewHolder(View itemView) {
super(itemView);
// Encontre os views por ID
}
}
}
2.1. Dependências dependencies { ... implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:cardview-v7:28.0.0' implementation 'com.google.android.material:material:1.1.0' } 2.2. MainActivity public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); RecyclerView recyclerView = findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(new WeatherAdapter(getSampleData())); } private List getSampleData() {
List weatherList = new ArrayList<>();
// Adicione exemplos de dados aqui
return weatherList;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_about) {
Intent intent = new Intent(this, AboutActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
2.3. RecyclerView Adapter public class WeatherAdapter extends RecyclerView.Adapter {
private List weatherList;
public WeatherAdapter(List weatherList) {
this.weatherList = weatherList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.weather_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Weather weather = weatherList.get(position);
// Configure os dados do item aqui
}
@Override
public int getItemCount() {
return weatherList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
// Inicialize os componentes do item aqui
public ViewHolder(View itemView) {
super(itemView);
// Encontre os views por ID
}
}
}
2.4. Layouts <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">
2.5. weather_item.xml <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp">
</androidx.cardview.widget.CardView> 2.6. activity_about.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".AboutActivity">
2.7. AboutActivity public class AboutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); } }
2.8. Menu
2.9. Adicione informações pessoais Adicione uma tela com as informações pessoais dentro da AboutActivity ou como uma nova Activity.
2.10. Material Design (cores e componentes)
2.10.1