0
我正在開發一個非常基礎的TimeTable應用程序作爲高中的研究項目,並遇到了一些我找不到解決方案的問題。如何使用EditTexts中的數據計劃每週通知?
我的主要(也是唯一的,就此而言)佈局由包含五個選項卡(星期一至星期五)的TabHost組成。
每個選項卡包含6行(六個不同時間)的水平線性佈局,其中包含兩個EditTexts:一個用於主題的標題,另一個用於類號。這意味着用戶可以在不同的編輯文本中輸入其個人數據。計劃在8:00的週一舉行的通知應該使用這些EditTexts的數據進行構建。
我想要做的是創建30個每週通知,從星期一到星期五每天6個。他們必須被觸發的時間是預先定義的,用戶將無法更改它。
Here is an image of the layout.
這是整個activity_main.xml中佈局複製30倍的基本代碼:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/first_time"
android:textSize="20sp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/subject_hint"
android:layout_marginStart="10dp"
android:inputType="number|textCapWords"
android:id="@+id/mon_subj_1" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/class_hint"
android:layout_marginStart="10dp"
android:id="@+id/mon_class_1" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_action_delete"
android:layout_marginStart="10dp"
android:contentDescription="@string/button_description"/>
</LinearLayout>
在MainActivity.java文件,我只添加必要的代碼來設置TabHost :
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//creating the TAB HOST
TabHost tabHost = (TabHost) findViewById(R.id.tabHost2);
tabHost.setup();
//setting up the 1st tab
TabHost.TabSpec tabSpec = tabHost.newTabSpec("monday");
tabSpec.setContent(R.id.monday);
tabSpec.setIndicator("Mon");
tabHost.addTab(tabSpec);
//setting up the 2nd tab
tabSpec = tabHost.newTabSpec("tuesday");
tabSpec.setContent(R.id.tuesday);
tabSpec.setIndicator("Tue");
tabHost.addTab(tabSpec);
//setting up the 3rd tab
tabSpec = tabHost.newTabSpec("wednesday");
tabSpec.setContent(R.id.wednesday);
tabSpec.setIndicator("Wed");
tabHost.addTab(tabSpec);
//setting up the 4th tab
tabSpec = tabHost.newTabSpec("thursday");
tabSpec.setContent(R.id.thursday);
tabSpec.setIndicator("Thu");
tabHost.addTab(tabSpec);
//setting up the 5th tab
tabSpec = tabHost.newTabSpec("friday");
tabSpec.setContent(R.id.friday);
tabSpec.setIndicator("Fri");
tabHost.addTab(tabSpec);
//here we have finished creating the TAB HOST
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
嘗試'AlarmManager' http://developer.android.com/reference/android/app/AlarmManager.html –
可能重複[在android中每週重複報警一次](http://stackoverflow.com/問題/ 16237382 /重複報警一次在一個週中,機器人) –