Reputation: 463
How can I create dynamic table when I do not know column quantity (I know only first three column), because this will be connected soccer toures, maybewill be four toures or five or more.
I have two LinearLayout:
I wanna make when I click "result" I wanna see on right side recyclerview(parsing json).
My Activity_england.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@drawable/stadium_background"
android:padding="8dp">
<!-- Left Side: Buttons -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:orientation="vertical"
android:padding="2dp">
<Button
android:id="@+id/btnBack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Back"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginBottom="10dp"
android:background="@drawable/button_background" />
<Button
android:id="@+id/btnResults"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Results"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginBottom="10dp"
android:background="@drawable/button_background" />
<Button
android:id="@+id/btnFixtures"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fixtures"
android:textColor="@android:color/white"
android:textStyle="bold"
android:layout_marginBottom="10dp"
android:background="@drawable/button_background" />
<Button
android:id="@+id/btnTeams"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Teams"
android:textColor="@android:color/white"
android:textStyle="bold"
android:layout_marginBottom="10dp"
android:background="@drawable/button_background" />
</LinearLayout>
<!-- Right Side: RecyclerView for Header + Data -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical"
android:padding="2dp">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp" />
</LinearLayout>
My json is:
[
{
"id": 0,
"rank_field": "Rank",
"team": "Team",
"p": "P",
"T_9": "T_9",
"T_8": "T_8",
"T_7": "T_7",
"T_6": "T_6",
"T_5": "T_5",
"T_4": "T_4",
"T_3": "T_3",
"T_2": "T_2",
"T_1": "T_1"
},
{
"id": 1,
"rank_field": "1",
"team": "Liverpool",
"p": "80",
"T_9": "W",
"T_8": "W",
"T_7": "W",
"T_6": "W",
"T_5": "D",
"T_4": "D",
"T_3": "L",
"T_2": "L",
"T_1": "L"
},
{
"id": 2,
"rank_field": "2",
"team": "Arsenal",
"p": "70",
"T_9": "W",
"T_8": "W",
"T_7": "W",
"T_6": "W",
"T_5": "D",
"T_4": "D",
"T_3": "L",
"T_2": "L",
"T_1": "L"
},
{
"id": 3,
"rank_field": "3",
"team": "Nottingham Forest",
"p": "50",
"T_9": "W",
"T_8": "W",
"T_7": "D",
"T_6": "D",
"T_5": "L",
"T_4": "L",
"T_3": "L",
"T_2": "W",
"T_1": "W"
},
{
"id": 4,
"rank_field": "4",
"team": "Manchester City",
"p": "49",
"T_9": "W",
"T_8": "W",
"T_7": "D",
"T_6": "D",
"T_5": "L",
"T_4": "L",
"T_3": "L",
"T_2": "W",
"T_1": "W"
},
ApiClien.java:
public class ApiClient {
private static final String BASE_URL = "http://10.0.2.2:8000/";
private static Retrofit retrofit;
public static Retrofit getClient() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
Apiservice.java:
public interface ApiService {
@GET("/MyHome/soccerdata/")
Call<List<TeamTableData>> getPremierLeagueData();
}
England_Activity.java:
public class EnglandActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private ResultAdapter adapter;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_england);
// Initialize buttons
Button btnResults = findViewById(R.id.btnResults);
Button btnFixtures = findViewById(R.id.btnFixtures);
Button btnTeams = findViewById(R.id.btnTeams);
Button btnBack = findViewById(R.id.btnBack);
// RecyclerView setup
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// ProgressBar
progressBar = findViewById(R.id.progressBar);
// Button actions
btnResults.setOnClickListener(v -> fetchResults());
btnBack.setOnClickListener(v -> finish());
btnFixtures.setOnClickListener(v -> {
Toast.makeText(this, "Fixtures button clicked!", Toast.LENGTH_SHORT).show();
});
btnTeams.setOnClickListener(v -> {
Toast.makeText(this, "Teams button clicked!", Toast.LENGTH_SHORT).show();
});
}
private void fetchResults() {
// code here
}
Upvotes: 0
Views: 34