main.xml ファイルと rows.xml ファイルに次のコードがあります。main.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:gravity="center"
android:text="Time">
</TextView>
<TextView
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Module">
</TextView>
<TextView
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Lecturer">
</TextView>
</TableRow>
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</TableLayout>
行.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*" >
<ListView
android:id="@+id/info"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/time"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:gravity="center" >
</TextView>
<TextView
android:id="@+id/module"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
</TextView>
<TextView
android:id="@+id/lecturer"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
</TextView>
</TableRow>
</TableLayout>
8 行ごと (0 から始まる) 曜日のテキストビューを追加したいと考えています。textview を main.xml ファイルに追加したい場合は textview を追加できますが、rows.xml ファイルに同じコードを入れて (それを main.xml ファイルから削除すると)、アプリは動作しません (エラーは発生しませんが、Eclipseは次のデバッグタブを表示します:)
Thread [<1> main] (Suspended (exception RuntimeException))
<VM does not provide monitor information>
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1651
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1667
ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 117
ActivityThread$H.handleMessage(Message) line: 935
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 130
ActivityThread.main(String[]) line: 3687
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 867
ZygoteInit.main(String[]) line: 625
NativeStart.main(String[]) line: not available [native method]
Thread [<8> Binder Thread #2] (Running)
Thread [<7> Binder Thread #1] (Running)
どこが間違っているのか、どうすれば修正できますか?
編集:ログキャット
01-18 02:44:14.656: W/ActivityThread(893): Application com.example.timetable is waiting for the debugger on port 8100...
01-18 02:44:14.664: I/System.out(893): Sending WAIT chunk
01-18 02:44:14.882: I/System.out(893): Debugger has connected
01-18 02:44:14.882: I/System.out(893): waiting for debugger to settle...
01-18 02:44:15.078: I/System.out(893): waiting for debugger to settle...
01-18 02:44:15.281: I/System.out(893): waiting for debugger to settle...
01-18 02:44:15.484: I/System.out(893): waiting for debugger to settle...
01-18 02:44:15.679: I/System.out(893): waiting for debugger to settle...
01-18 02:44:15.898: I/System.out(893): waiting for debugger to settle...
01-18 02:44:16.093: I/System.out(893): waiting for debugger to settle...
01-18 02:44:16.296: I/System.out(893): debugger has settled (1410)
01-18 02:44:16.476: I/ApplicationPackageManager(893): cscCountry is not German : VDI
動的テキストビューのコード
View linearLayout = findViewById(R.id.info);
int a = 0;
while(x < 41)
{
//The textview is only printed out every 8 rows because there is only 8 classes a day and the day is printed out at the start
if(x == 0 || x == 8 || x == 16 || x == 24 || x == 32)
{
TextView valueTV = new TextView(this);
valueTV.setText(fetch2.get(a)); //fetch2 has the days of the week stored in it
valueTV.setId(x);
valueTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
a++;
((LinearLayout) linearLayout).addView(valueTV);
x++;
}
else
{
lv = (ListView) findViewById(R.id.listview);
adapter = new CustomAdapter(MainActivity.this, R.id.listview, fetch); //fetch has the time, module and lecturer stored
lv.setAdapter(adapter);
x++;
}
}
編集: Main.java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.LinearLayout;
public class Main extends Activity {
private ListView lv;
private CustomAdapter adapter;
private ArrayList<Custom> fetch = new ArrayList<Custom>();
private ArrayList<String> fetch2 = new ArrayList<String>();
private int x = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fetch2.add("Monday");
fetch2.add("Tuesday");
fetch2.add("Wednesday");
fetch2.add("Thursday");
fetch2.add("Friday");
InputStream inputStream = getResources().openRawResource(R.raw.timetable);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int ctr;
try {
ctr = inputStream.read();
while (ctr != -1) {
byteArrayOutputStream.write(ctr);
ctr = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
//Parse the data into jsonobject to get original data in form of json.
JSONObject jObject = new JSONObject(byteArrayOutputStream.toString());
//Grabs the data for each day
JSONArray Monday = jObject.getJSONArray("Monday");
JSONArray Tuesday = jObject.getJSONArray("Tuesday");
JSONArray Wednesday = jObject.getJSONArray("Wednesday");
JSONArray Thursday = jObject.getJSONArray("Thursday");
JSONArray Friday = jObject.getJSONArray("Friday");
String time= "";
String module = "";
String lecturer = "";
//Adding each days data
for (int i = 0; i < Monday.length(); i++)
{
time = Monday.getJSONObject(i).getString("time");
module = Monday.getJSONObject(i).getString("module");
lecturer = Monday.getJSONObject(i).getString("lecturer");
Custom a = new Custom(time, module, lecturer);
fetch.add(a);
}
for (int i = 0; i < Tuesday.length(); i++)
{
time = Tuesday.getJSONObject(i).getString("time");
module = Tuesday.getJSONObject(i).getString("module");
lecturer = Tuesday.getJSONObject(i).getString("lecturer");
Custom a = new Custom(time, module, lecturer);
fetch.add(a);
}
for (int i = 0; i < Wednesday.length(); i++)
{
time = Wednesday.getJSONObject(i).getString("time");
module = Wednesday.getJSONObject(i).getString("module");
lecturer = Wednesday.getJSONObject(i).getString("lecturer");
Custom a = new Custom(time, module, lecturer);
fetch.add(a);
}
for (int i = 0; i < Thursday.length(); i++)
{
time = Thursday.getJSONObject(i).getString("time");
module = Thursday.getJSONObject(i).getString("module");
lecturer = Thursday.getJSONObject(i).getString("lecturer");
Custom a = new Custom(time, module, lecturer);
fetch.add(a);
}
for (int i = 0; i < Friday.length(); i++)
{
time = Friday.getJSONObject(i).getString("time");
module = Friday.getJSONObject(i).getString("module");
lecturer = Friday.getJSONObject(i).getString("lecturer");
Custom a = new Custom(time, module, lecturer);
fetch.add(a);
}
} catch (Exception e) {
e.printStackTrace();
}
View linearLayout = findViewById(R.id.info);
int a = 0;
while(x < 41)
{
//The textview is only printed out every 8 rows because there is only 8 classes a day and the day is printed out at the start
if(x == 0 || x == 8 || x == 16 || x == 24 || x == 32)
{
TextView valueTV = new TextView(this);
valueTV.setText(fetch2.get(a));
valueTV.setId(x);
valueTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
a++;
((LinearLayout) linearLayout).addView(valueTV);
}
else
{
//Adding each days data
lv = (ListView) findViewById(R.id.listview);
adapter = new CustomAdapter(MainActivity.this, R.id.listview, fetch);
lv.setAdapter(adapter);
x++;
}
}
}
}