Skip to content

Commit ae4825c

Browse files
committed
commit
1 parent 553b8ac commit ae4825c

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

app/src/main/java/com/example/webapplicationwithspring/EventsActivity.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package com.example.webapplicationwithspring;
22

3+
import android.content.Context;
34
import android.content.Intent;
45
import android.os.Bundle;
56
import android.util.Log;
67
import android.view.MenuItem;
8+
import android.view.View;
9+
import android.widget.LinearLayout;
710
import android.widget.ScrollView;
811
import android.widget.TextView;
912
import android.widget.Toast;
1013

1114
import androidx.annotation.NonNull;
1215
import androidx.annotation.Nullable;
1316
import androidx.appcompat.app.AppCompatActivity;
14-
import androidx.constraintlayout.widget.ConstraintLayout;
1517

1618
import com.android.volley.Request;
1719
import com.android.volley.RequestQueue;
@@ -63,12 +65,9 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
6365
public void onCreate(@Nullable Bundle savedInstanceState){
6466
super.onCreate(savedInstanceState);
6567
setContentView(R.layout.activity_events);
66-
eventData = findViewById(R.id.event_data);
6768
scrollView = findViewById(R.id.scroll_view);
69+
final LinearLayout linearLayout = findViewById(R.id.scroll_layout);
6870
RequestQueue requestQueue = Volley.newRequestQueue(this);
69-
final TextView tv = new TextView(this);
70-
tv.setLayoutParams(new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT,
71-
ConstraintLayout.LayoutParams.WRAP_CONTENT));
7271
JsonArrayRequest objectRequest = new JsonArrayRequest(
7372
Request.Method.GET,
7473
url,
@@ -78,14 +77,16 @@ public void onCreate(@Nullable Bundle savedInstanceState){
7877
public void onResponse(JSONArray response) {
7978
try {
8079
for (int i = 0; i < response.length(); i++) {
80+
81+
8182
JSONObject jo = (JSONObject) response.get(i);
8283
String eventName = jo.getString("eventName");
8384
String eventDate = jo.getString("eventDate");
8485
String eventDescription = jo.getString("eventDescription");
8586
String eventPlace = jo.getString("eventPlace");
86-
eventData.append(eventName + " at " + eventDate + " there will be " + eventDescription + " in " + eventPlace);
87-
88-
87+
//eventData.append(eventName + " at " + eventDate + " there will be " + eventDescription + " in " + eventPlace);
88+
TextView tv = getTextView(EventsActivity.this,eventName + " at " + eventDate + " there will be " + eventDescription + " in " + eventPlace);
89+
linearLayout.addView(tv);
8990
}
9091
} catch (JSONException e) {
9192
e.printStackTrace();
@@ -95,7 +96,8 @@ public void onResponse(JSONArray response) {
9596
new Response.ErrorListener() {
9697
@Override
9798
public void onErrorResponse(VolleyError error) {
98-
Toast.makeText(EventsActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
99+
TextView tv = getTextView(EventsActivity.this, "Server does not response");
100+
linearLayout.addView(tv);
99101
Log.d("EventSSS",error.toString());
100102
}
101103
}
@@ -106,4 +108,19 @@ public void onErrorResponse(VolleyError error) {
106108
nView.setOnNavigationItemSelectedListener(navListener);
107109
nView.setSelectedItemId(R.id.nav_events);
108110
}
111+
112+
public TextView getTextView(Context context,String text){
113+
final TextView tv = new TextView(context);
114+
tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
115+
tv.setTextSize(30);
116+
tv.setText(text);
117+
tv.setOnClickListener(new View.OnClickListener() {
118+
@Override
119+
public void onClick(View v) {
120+
Toast.makeText(EventsActivity.this, "you have clicked on event", Toast.LENGTH_SHORT).show();
121+
}
122+
});
123+
return tv;
124+
125+
}
109126
}
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
45
android:id="@+id/constraint_layout"
6+
android:orientation="vertical"
7+
android:paddingLeft="3dp"
8+
android:paddingRight="3dp"
59
android:layout_width="match_parent"
610
android:layout_height="match_parent">
711

@@ -10,18 +14,18 @@
1014
android:layout_width="match_parent"
1115
android:layout_height="0dp"
1216
android:id = "@+id/scroll_view"
17+
android:padding="10dp"
18+
android:layout_weight="1"
19+
android:gravity="top"
1320
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation_for_events"
1421
app:layout_constraintTop_toTopOf="parent">
15-
<TextView
22+
<LinearLayout
1623
android:layout_width="match_parent"
1724
android:layout_height="wrap_content"
18-
android:padding="5dp"
19-
android:textSize="24sp"
20-
android:hint="Text will be here"
21-
android:id="@+id/event_data1"
22-
android:visibility="visible"
23-
/>
24-
25+
android:orientation="vertical"
26+
android:id="@+id/scroll_layout"
27+
android:layout_margin="5dp">
28+
</LinearLayout>
2529
</ScrollView>
2630

2731

@@ -30,10 +34,7 @@
3034
android:layout_width="match_parent"
3135
android:layout_height="wrap_content"
3236
android:background="#00FFFFFF"
33-
app:layout_constraintBottom_toBottomOf="parent"
34-
app:layout_constraintStart_toStartOf="parent"
35-
app:layout_constraintTop_toTopOf="parent"
36-
app:layout_constraintVertical_bias="1.0"
37+
android:layout_gravity="bottom"
3738
app:menu="@menu/bottom_navigation" />
3839

39-
</androidx.constraintlayout.widget.ConstraintLayout>
40+
</LinearLayout>

app/src/main/res/layout/activity_map.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout
2+
<LinearLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
55
xmlns:tools="http://schemas.android.com/tools"
@@ -15,8 +15,7 @@
1515
android:name="com.google.android.gms.maps.SupportMapFragment"
1616
android:layout_width="match_parent"
1717
android:layout_height="0dp"
18-
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
19-
app:layout_constraintTop_toTopOf="parent"
18+
android:layout_weight="1"
2019
tools:context=".MapActivity" />
2120

2221

@@ -27,9 +26,6 @@
2726
android:layout_gravity="bottom"
2827

2928
android:background="#00FFFFFF"
30-
app:layout_constraintBottom_toBottomOf="parent"
31-
app:layout_constraintStart_toStartOf="parent"
32-
app:layout_constraintTop_toTopOf="parent"
3329
app:layout_constraintVertical_bias="1.0"
3430
app:menu="@menu/bottom_navigation" />
3531
<!---->
@@ -39,4 +35,4 @@
3935
<!--
4036
4137
-->
42-
</androidx.constraintlayout.widget.ConstraintLayout>
38+
</LinearLayout>

0 commit comments

Comments
 (0)