implemented ListView
This commit is contained in:
parent
826964792d
commit
6537d97d8a
|
@ -4,7 +4,7 @@ public class Location {
|
|||
|
||||
private String location;
|
||||
private String city;
|
||||
private String county:
|
||||
private String county;
|
||||
|
||||
|
||||
public Location(String location, String city, String county) {
|
||||
|
|
|
@ -5,27 +5,43 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import at.fhj.airkoality.R;
|
||||
import at.fhj.airkoality.model.Location;
|
||||
import at.fhj.airkoality.ui.adapter.LocationListAdapter;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private TextView tvTest;
|
||||
private BottomNavigationView bottomNavigationView;
|
||||
private RecyclerView locationList;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
tvTest = findViewById(R.id.tvTest);
|
||||
bottomNavigationView = findViewById(R.id.bnvMain);
|
||||
|
||||
bottomNavigationView.setOnNavigationItemSelectedListener(menuItem -> {
|
||||
tvTest.setText(menuItem.getTitle());
|
||||
return true;
|
||||
});
|
||||
locationList = findViewById(R.id.rvLocationList);
|
||||
List<Location> locations = new ArrayList<>();
|
||||
|
||||
locations.add(new Location("Daheim", "Graz" , "Österreich"));
|
||||
locations.add(new Location("Daheim2", "Graz" , "Österreich"));
|
||||
locations.add(new Location("Daheim3", "Graz" , "Österreich"));
|
||||
locations.add(new Location("Daheim4", "Graz" , "Österreich"));
|
||||
locations.add(new Location("Daheim5", "Graz" , "Österreich"));
|
||||
locations.add(new Location("Daheim6", "Graz" , "Österreich"));
|
||||
locations.add(new Location("Daheim7", "Graz" , "Österreich"));
|
||||
locations.add(new Location("Daheim8", "Graz" , "Österreich"));
|
||||
|
||||
LocationListAdapter adapter = new LocationListAdapter(locations);
|
||||
|
||||
locationList.setAdapter(adapter);
|
||||
locationList.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class SplashActivity extends AppCompatActivity {
|
|||
startActivity(intent);
|
||||
|
||||
}
|
||||
},5000);
|
||||
},3000);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
package at.fhj.airkoality.ui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import at.fhj.airkoality.R;
|
||||
import at.fhj.airkoality.model.Location;
|
||||
|
||||
public class LocationListAdapter extends RecyclerView.Adapter<LocationListAdapter.LocationItemViewHolder> {
|
||||
|
||||
|
||||
private List<Location> locations;
|
||||
|
||||
public LocationListAdapter(List<Location> locations){
|
||||
this.locations = locations;
|
||||
}
|
||||
|
@ -21,11 +27,19 @@ public class LocationListAdapter extends RecyclerView.Adapter<LocationListAdapte
|
|||
@NonNull
|
||||
@Override
|
||||
public LocationItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
||||
return null;
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.location_list_item,viewGroup,false);
|
||||
|
||||
return new LocationItemViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull LocationItemViewHolder locationItemViewHolder, int i) {
|
||||
public void onBindViewHolder(@NonNull LocationItemViewHolder locationItemViewHolder, int position) {
|
||||
|
||||
Context context = locationItemViewHolder.tvLocation.getContext();
|
||||
|
||||
locationItemViewHolder.tvLocation.setText(context.getString(R.string.location_label) + " " + locations.get(position).getLocation());
|
||||
locationItemViewHolder.tvCity.setText(context.getString(R.string.city_label) + " " + locations.get(position).getLocation());
|
||||
locationItemViewHolder.tvCountry.setText(context.getString(R.string.country_label) + " " + locations.get(position).getLocation());
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,8 +49,21 @@ public class LocationListAdapter extends RecyclerView.Adapter<LocationListAdapte
|
|||
}
|
||||
|
||||
class LocationItemViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
CardView cvLocationItem;
|
||||
TextView tvLocation;
|
||||
TextView tvCity;
|
||||
TextView tvCountry;
|
||||
|
||||
|
||||
public LocationItemViewHolder(@NonNull View itemView){
|
||||
super(itemView);
|
||||
|
||||
cvLocationItem = itemView.findViewById(R.id.cvLocationItem);
|
||||
tvLocation = itemView.findViewById(R.id.tvlocation);
|
||||
tvCity = itemView.findViewById(R.id.tvCity);
|
||||
tvCountry = itemView.findViewById(R.id.tvCountry);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
|
||||
|
||||
<!--<TextView
|
||||
android:id="@+id/tvTest"
|
||||
android:text="Hallo Welt"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content" />-->
|
||||
|
||||
<android.support.design.widget.BottomNavigationView
|
||||
android:id="@+id/bnvMain"
|
||||
|
@ -25,5 +27,12 @@
|
|||
|
||||
</android.support.design.widget.BottomNavigationView>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/rvLocationList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_above="@+id/bnvMain"
|
||||
></android.support.v7.widget.RecyclerView>
|
||||
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,8 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/cvLocationItem"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_margin="5dp"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
|
@ -11,17 +13,21 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:textSize="25sp"
|
||||
android:padding="10dp"
|
||||
android:id="@+id/tvlocation"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:padding="10dp"
|
||||
android:id="@+id/tvCity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tcCountry"
|
||||
android:padding="10dp"
|
||||
android:id="@+id/tvCountry"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
|
|
@ -3,4 +3,7 @@
|
|||
<string name="location">Location</string>
|
||||
<string name="map">Map</string>
|
||||
<string name="airkoality">AirKoality</string>
|
||||
<string name="location_label">Location:</string>
|
||||
<string name="city_label">City:</string>
|
||||
<string name="country_label">Country:</string>
|
||||
</resources>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
- Hinzufügen der Activities in der AndroidManifest.xml Datei
|
||||
- strings.xml kennengelernt um Texte einer App zentral verwalten zu können
|
||||
|
||||
## 08.03.2019
|
||||
## 08.03.2019 - Lab 3
|
||||
|
||||
Context -> weiß was in der App gerade "abgeht" (Java Objekt)
|
||||
- Activity oder Application
|
||||
|
@ -39,4 +39,8 @@ Context -> weiß was in der App gerade "abgeht" (Java Objekt)
|
|||
|
||||
Best Practise kennengelernt um große Listen darzustellen
|
||||
|
||||
Liste bekommt einen Adapter und stellt dann nur Listenelemente dar, die gerade am Bildschrim angezeigt werden.
|
||||
|
||||
Card View Layout ausprobiert
|
||||
|
||||
Fragments ->
|
Loading…
Reference in New Issue