我必须让以下代码适用于学校项目。"周活动"应该稍后显示一个时间表。
但是,有两个小错误:由于某种原因,"final TableRow table = (TableRow) findViewById(R.id.tableRowDays);"无法在此类中解决,但 Android Studio 不会给我任何提示可能是什么问题。
最后一个方法中的小 Intent 链接到其他活动也不起作用。安卓工作室说它无法解析意图的构造函数?:?
如果你们中的任何人看到我没有看到的东西,任何帮助将不胜感激。我被困在这里,也承受着时间压力。>_<;
public class WeekActivity extends AppCompatActivity {
List<DatensatzStundenplan> inhalte;
int anzahlTage = 5;
int anzahlStundenMax = 11;
StundenplanTabelle tabelle;
ScaleGestureDetector.SimpleOnScaleGestureListener scaleGestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_week);
scaleGestureDetector = new OnScaleGestureListenerWeek();
//techotopia SimpleOnScaleGestureListener
final TableRow table = (TableRow) findViewById(R.id.tableRowDays);
TextView tv;
tv = (TextView) table.findViewById(R.id.day1);
tv.setText("Mo");
tv = (TextView) table.findViewById(R.id.day2);
tv.setText("Di");
tv = (TextView) table.findViewById(R.id.day3);
tv.setText("Mi");
tv = (TextView) table.findViewById(R.id.day4);
tv.setText("Do");
tv = (TextView) table.findViewById(R.id.day5);
tv.setText("Fr");
tabelle = new StundenplanTabelle();
System.out.println(tabelle.getRows());
inhalte = tabelle.getRows();
faecherEintragen(this);
}
private void faecherEintragen(Context context) {
final ListView weekTable = (ListView) findViewById(R.id.weekTable);
LayoutInflater li = LayoutInflater.from(context);
for(int i = 0; i<anzahlStundenMax; i++){
View tr = li.inflate(R.layout.table_row_subjects, null, false);
TextView tv;
tv = (TextView) tr.findViewById(R.id.cell_1);
tv.setText(inhalte.get(i).getFachMo());
tv = (TextView) tr.findViewById(R.id.cell_2);
tv.setText(inhalte.get(i).getFachDi());
tv = (TextView) tr.findViewById(R.id.cell_3);
tv.setText(inhalte.get(i).getFachMi());
tv = (TextView) tr.findViewById(R.id.cell_4);
tv.setText(inhalte.get(i).getFachDo());
tv = (TextView) tr.findViewById(R.id.cell_5);
tv.setText(inhalte.get(i).getFachFr());
weekTable.addView(tr);
}
}
private void buttonPressed(){
Intent i;
i = new Intent(this, DayActivity.class);
startActivity(i);
}
}
这是 xml 文件activity_week:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableLayout
android:id="@+id/tableDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:id="@+id/tableRowDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/day1"
android:textColor="#29088A"
android:text="MO"
android:textSize="@dimen/abc_text_size_large_material"
android:width="80dp"
/>
<TextView
android:id="@+id/day2"
android:textColor="#29088A"
android:text="DI"
android:textSize="@dimen/abc_text_size_large_material"
android:width="80dp"
/>
<TextView
android:id="@+id/day3"
android:textColor="#29088A"
android:text="MI"
android:textSize="@dimen/abc_text_size_large_material"
android:width="80dp"
/>
<TextView
android:id="@+id/day4"
android:textColor="#29088A"
android:text="DO"
android:textSize="@dimen/abc_text_size_large_material"
android:width="80dp"
/>
<TextView
android:id="@+id/day5"
android:textColor="#29088A"
android:text="FR"
android:textSize="22sp"
android:width="80dp"
/>
</TableRow>
</TableLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/weekTable"
android:layout_above="@+id/tableDays"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<!-- <TableLayout
android:id="@+id/weekTable"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TableLayout>-->
</RelativeLayout>
</ScrollView>
</RelativeLayout>
。这是table_row_subjects.xml,以防万一应该是相关的:
<?xml version="1.0" encoding="UTF-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:focusable="true"
android:focusableInTouchMode="false"
android:clickable="true"
android:id="@+id/tableRowSubjects"
>
<TextView
android:id="@+id/cell_1"
android:width="80dp"
android:text="TEST"
/>
<TextView
android:id="@+id/cell_2"
android:width="80dp"
/>
<TextView
android:id="@+id/cell_3"
android:width="80dp"
/>
<TextView
android:id="@+id/cell_4"
android:width="80dp"
/>
<TextView
android:id="@+id/cell_5"
android:width="80dp"
/>
</TableRow>
。和清单,根据要求:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.dbg.aylin.stundenplan" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".WeekActivity"
android:label="WeekActivity"
android:theme="@style/Theme.AppCompat.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DayActivity"
android:label="DayActivity"
android:theme="@style/Theme.AppCompat.Light"/>
</application>
</manifest>
change your code to this..
final TableRow table = (TableRow) findViewById(R.id.tableRowSubjects);
TextView tv;
tv = (TextView) table.findViewById(R.id.cell_1);
tv.setText("Mo");
tv = (TextView) table.findViewById(R.id.cell_2);
tv.setText("Di");
tv = (TextView) table.findViewById(R.id.cell_3);
tv.setText("Mi");
tv = (TextView) table.findViewById(R.id.cell_4);
tv.setText("Do");
tv = (TextView) table.findViewById(R.id.cell_5);
tv.setText("Fr");
尝试在公共类 WeekActivity 下声明 TextView TV 权限。清单文件中的 DayActivity 类需要如下所示:
<activity
android:name=".DayActivity"
android:label="DayActivity"
android:theme="@style/Theme.AppCompat.Light">
<intent-filter>
<action android:name="de.dbg.aylin.stundenplan.dayactivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
然后你可以像这样计算意图:
Intent i = new Intent("de.dbg.aylin.stundenplan.dayactivity");
startActivity(i);