Reputation: 138
So I have a little problem with my app. I am adding the same layout 11 times to my main layout and here I am adding text to them. The Problem is, that no text shows up at all. Sorry for my not perfect english. :D
JSONParser parser = new JSONParser();
HashMap<String, String> params = new HashMap<>();
params.put("username", username);
params.put("pass", password);
JSONObject json = parser.makeHttpRequest(link to php file, params);
ArrayList<String> stundenList = new ArrayList<>();
int success = json.getInt("success");
if (success == 1) {
JSONArray stunden = json.getJSONArray("stundenplan");
for (int i = 0; i < stunden.length(); i++) {
JSONObject c = stunden.getJSONObject(i);
String montag = c.getString("montag");
String dienstag = c.getString("dienstag");
String mittwoch = c.getString("mittwoch");
String donnerstag = c.getString("donnerstag");
String freitag = c.getString("freitag");
stundenList.add(montag);
stundenList.add(dienstag);
stundenList.add(mittwoch);
stundenList.add(donnerstag);
stundenList.add(freitag);
}
for(int i = 0; i < getRows().size(); i++) {
LinearLayout ll = (LinearLayout) Karo.main.findViewById(getRows().get(i));
TextView column1 = (TextView) ll.findViewById(R.id.column1);
TextView column2 = (TextView) ll.findViewById(R.id.column1);
TextView column3 = (TextView) ll.findViewById(R.id.column1);
TextView column4 = (TextView) ll.findViewById(R.id.column1);
TextView column5 = (TextView) ll.findViewById(R.id.column1);
TextView column6 = (TextView) ll.findViewById(R.id.column1);
TextView column7 = (TextView) ll.findViewById(R.id.column1);
TextView column8 = (TextView) ll.findViewById(R.id.column1);
TextView column9 = (TextView) ll.findViewById(R.id.column1);
TextView column10 = (TextView) ll.findViewById(R.id.column1);
TextView column11 = (TextView) ll.findViewById(R.id.column1);
column1.setText(stundenList.get(i).split(";")[0]);
column2.setText(stundenList.get(i).split(";")[1]);
column3.setText(stundenList.get(i).split(";")[2]);
column4.setText(stundenList.get(i).split(";")[3]);
column5.setText(stundenList.get(i).split(";")[4]);
column6.setText(stundenList.get(i).split(";")[5]);
column7.setText(stundenList.get(i).split(";")[6]);
column8.setText(stundenList.get(i).split(";")[7]);
column9.setText(stundenList.get(i).split(";")[8]);
column10.setText(stundenList.get(i).split(";")[9]);
column11.setText(stundenList.get(i).split(";")[10]);
}
}
getRows function:
private static List<Integer> getRows() {
List<Integer> rows = new ArrayList<>();
rows.add(R.id.stundenplan_montag);
rows.add(R.id.stundenplan_dienstag);
rows.add(R.id.stundenplan_mittwoch);
rows.add(R.id.stundenplan_donnerstag);
rows.add(R.id.stundenplan_freitag);
return rows;
}
main layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/verplan"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Karo"
tools:showIn="@layout/app_bar_main">
<ViewFlipper
android:id="@+id/ViewFlipp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home Text" />
</RelativeLayout>
<LinearLayout
android:id="@+id/view2"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/stundenplan_montag" layout="@layout/plantextviews"/>
<include android:id="@+id/stundenplan_dienstag" layout="@layout/plantextviews" android:layout_width="40dp" android:layout_height="wrap_content" />
<include android:id="@+id/stundenplan_mittwoch" layout="@layout/plantextviews" android:layout_width="40dp" android:layout_height="wrap_content" />
<include android:id="@+id/stundenplan_donnerstag" layout="@layout/plantextviews" android:layout_width="40dp" android:layout_height="wrap_content"/>
<include android:id="@+id/stundenplan_freitag" layout="@layout/plantextviews" android:layout_width="40dp" android:layout_height="wrap_content" />
</LinearLayout>
</ViewFlipper>
plantextviews layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column1" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column2" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column3" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column4" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column5" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column6" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column7" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column8" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column9" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column10" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/column11" />
Upvotes: 1
Views: 42
Reputation: 11982
The problem is that you are finding view by id = R.id.column1
11 times, but you should find views with ids R.id.column1
, R.id.column2
, R.id.column3
and so on:
...
for(int i = 0; i < getRows().size(); i++) {
LinearLayout ll = (LinearLayout) Karo.main.findViewById(getRows().get(i));
TextView column1 = (TextView) ll.findViewById(R.id.column1);
TextView column2 = (TextView) ll.findViewById(R.id.column2);
TextView column3 = (TextView) ll.findViewById(R.id.column3);
...
...
column1.setText(stundenList.get(i).split(";")[0]);
column2.setText(stundenList.get(i).split(";")[1]);
column3.setText(stundenList.get(i).split(";")[2]);
...
...
}
Upvotes: 2